python链接redis
一个简单的连接redis,并通过key查询对应的value值。
# -*- encoding: UTF-8 -*- __author__ = "Sky" import redis,json def to_redis(audit_content,num): pool = redis.ConnectionPool(host='', port=6379, password="", db=0) conn = redis.Redis(connection_pool=pool) # print(conn.get("member:agent_id:10099")) result = conn.hget('check', 'realtime:agent_id:10099') if result is not None: result = eval(result) for i in range(len(result)): if result[i][audit_content] == num: print(json.dumps(result[i], indent=4, ensure_ascii=False)) else: pass else: print('redis查询没有结果') if __name__ =="__main__": audit_content = "audit_content" #规则纬度编号 num = "0" to_redis(audit_content, num)