forked from wintests/flaskDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
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
5 changed files
with
162 additions
and
15 deletions.
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,10 @@ | ||
import hashlib | ||
from config.setting import MD5_SALT | ||
|
||
|
||
def get_md5(username, str): | ||
"""MD5加密处理""" | ||
str = username + str + MD5_SALT # 把用户名也作为str加密的一部分 | ||
md5 = hashlib.md5() # 创建md5对象 | ||
md5.update(str.encode("utf-8")) # Python3中需要先转换为 bytes 类型,才能加密 | ||
return md5.hexdigest() # 返回密文 |
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,24 @@ | ||
import redis | ||
from config.setting import REDIS_HOST, REDIS_PORT, REDIS_PASSWD, EXPIRE_TIME | ||
|
||
|
||
class RedisDb(): | ||
|
||
def __init__(self, host, port, passwd): | ||
# 建立数据库连接 | ||
self.r = redis.Redis( | ||
host=host, | ||
port=port, | ||
password=passwd, | ||
decode_responses=True # get() 得到字符串类型的数据 | ||
) | ||
|
||
def handle_redis_token(self, key, value=None): | ||
if value: # 如果value非空,那么就设置key和value,EXPIRE_TIME为过期时间 | ||
self.r.set(key, value, ex=EXPIRE_TIME) | ||
else: # 如果value为空,那么直接通过key从redis中取值 | ||
redis_token = self.r.get(key) | ||
return redis_token | ||
|
||
|
||
redis_db = RedisDb(REDIS_HOST, REDIS_PORT, REDIS_PASSWD) |
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