-
-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from pymongo import MongoClient | ||
import pymysql | ||
import redis | ||
import os | ||
import datetime | ||
env_dist = os.environ | ||
try: | ||
client = MongoClient(env_dist.get("BILIOB_MONGO_URL")) | ||
db = client['biliob'] # 获得数据库的句柄 | ||
except Exception: | ||
print('{} MongoDB链接失败'.format(datetime.datetime.now())) | ||
os.system('systemctl restart mongod') | ||
|
||
redis_connect_string = env_dist.get("BILIOB_REDIS_CONNECTION_STRING") | ||
redis_list = redis_connect_string.split(":") | ||
pass_and_ip = redis_list[2].split('@') | ||
password = pass_and_ip[0] | ||
redis_ip = pass_and_ip[1] | ||
redis_port = redis_list[-1] | ||
pool = redis.ConnectionPool(password) # 实现一个连接池 | ||
redis_connection = redis.Redis( | ||
host=redis_ip, port=redis_port, password=password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from pymongo import MongoClient | ||
|
||
settings = { | ||
'MINGO_USER': 'jannchie', | ||
'MONGO_PSW': '141421', | ||
'MINGO_HOST': '127.0.0.1' | ||
} | ||
# 链接mongoDB | ||
client = MongoClient(settings['MINGO_HOST'], 27017) | ||
# 数据库登录需要帐号密码 | ||
client.admin.authenticate(settings['MINGO_USER'], settings['MONGO_PSW']) | ||
db = client['biliob'] # 获得数据库的句柄 | ||
|