Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
meanspec-hwinfo-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MeanSpec (SCE338 2024-2 Group 1)
meanspec-hwinfo-daemon
Commits
edca3de9
Verified
Commit
edca3de9
authored
6 months ago
by
Eunhak Lee
Browse files
Options
Downloads
Patches
Plain Diff
chore: Redis, PostgreSQL 연결을 유틸로 분리함
parent
4f2105a0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils.py
+36
-0
36 additions, 0 deletions
utils.py
with
36 additions
and
0 deletions
utils.py
0 → 100644
+
36
−
0
View file @
edca3de9
import
os
import
sys
import
traceback
import
redis
import
psycopg2
def
env_connect_redis
():
_redis_url
=
os
.
getenv
(
"
REDIS_URL
"
,
"
redis://localhost:6379/
"
)
print
(
"
Connecting Redis to
"
,
_redis_url
)
try
:
R
=
redis
.
Redis
.
from_url
(
_redis_url
)
_
=
R
.
keys
()
print
(
"
Successfully connected Redis.
"
)
return
R
except
:
print
(
"
Failed to connect Redis.
"
,
traceback
.
format_exc
(),
file
=
sys
.
stderr
)
def
env_connect_postgresql
():
_db_host
=
os
.
getenv
(
"
DB_HOST
"
,
"
localhost
"
)
_db_port
=
int
(
os
.
getenv
(
"
DB_PORT
"
,
"
5432
"
))
_db_name
=
os
.
getenv
(
"
DB_NAME
"
,
"
meanspec
"
)
_db_user
=
os
.
getenv
(
"
DB_USER
"
,
"
meanspec
"
)
_db_pass
=
os
.
getenv
(
"
DB_PASS
"
,
"
foopassword123
"
)
print
(
"
Connecting PostgreSQL to
"
,
_db_host
,
_db_port
,
_db_name
,
_db_user
)
try
:
db_conn
=
psycopg2
.
connect
(
host
=
_db_host
,
port
=
_db_port
,
dbname
=
_db_name
,
user
=
_db_user
,
password
=
_db_pass
)
return
db_conn
except
:
print
(
"
Failed to connect PostgreSQL.
"
,
traceback
.
format_exc
(),
file
=
sys
.
stderr
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment