1、python连接redis操作数据
0 1 2 3 4 5 6 7 8 9 |
#!/usr/bin/env python # -*- coding:utf8 -*- import redis r = redis.Redis(host='localhost', port=6379, db=0) r.set('foo', 'Bar') print (r.get('foo')) # 输出 Bar |
2、python连接redis操作线程池
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/usr/bin/env python # -*- coding:utf8 -*- import redis pool = redis.ConnectionPool(host='localhost', port=6379, db=0) r = redis.Redis(connection_pool=pool) pipe = r.pipeline() pipe_size = 100000 r.set('foo2', 'Bar2') print (r.get('foo2')) # 输出 Bar2 pipe = r.pipeline() pipe_size = 100000 |
3、decode_responses=True:这样写存的数据是字符串格式
0 1 2 |
import redis r = redis.Redis('127.0.0.1', 6379,decode_responses=True) |
4、获取库中所有键名
0 1 |
keys = r.keys() print(keys) |