word_cloud_bot/test/connector.py
机器人总动员 14e8e7f627 init
2021-05-05 10:59:30 +08:00

22 lines
607 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import redis
# 连接 redis
# 指定主机地址port与服务器连接redis默认数据库有16个默认db是0
# r = redis.Redis(host='127.0.0.1', port=6379, encoding='utf8', decode_responses=True) # password='**'
# print(r.get('foo'))
# r.set('foo', '[1,2,3]')
# print(r.get('foo'))
# print(r.keys())
# r.delete('foo')
# print(r.keys())
pool = redis.ConnectionPool(host='127.0.0.1', port=6379, encoding='utf8', decode_responses=True)
# r = redis.Redis(connection_pool=pool)
# r.set('foo', 'Bar')
# print(r.get('foo'))
def get_connection():
return redis.StrictRedis(connection_pool=pool)