python 链接redis 获取对应的值
import json import redis from common.logger import Logger from common.redisEnv import redisQA def getRedisKeyValue(env, key): enviroment = env hostname = enviroment['redis_hostname'] password = enviroment['redis_pwd'] key01 = key conn = redis.Redis(host=hostname, port=6379, password=password) # conn.get("x1", "hello", ex=5) # ex代表seconds,px代表ms val = conn.get(key01) Logger.info('获取到的缓存是{}'.format(val)) smsCode = str(val, encoding="utf8") return smsCode if __name__ == "__main__": env = redisQA mobile = "19900000001" # accessToken = getClientToken(env, mobile) # print(accessToken) key = 'PXXX' result = getRedisKeyValue(env, key) print(type(result)) print(result) print(json.dumps(result))
------------------------- A little Progress a day makes you a big success... ----------------------------