发布时间:2019-09-07 08:08:10编辑:auto阅读(1353)
import redis
"""
连接redis ConnectionPool 方式连接
"""
def connRedis(self):
pool=redis.ConnectionPool(host='172.16.1.2',password='',db=2, port=6379) #按具体情况填写参数
r=redis.StrictRedis(connection_pool=pool)
r.set("test_name","admin")
print(r.get('test_name'))
python 操作redis 集群 用redis模块不行,需要导入模块
# pip install redis-py-cluster
#!/usr/bin/env python
#coding:utf-8
from rediscluster import StrictRedisCluster
import sys
def redis_cluster():
redis_nodes = [{'host':'192.168.1.2','port':6378},
{'host':'192.168.1.2','port':6380},
{'host':'192.168.1.2','port':6381},
{'host':'192.168.1.2','port':6382},
{'host':'192.168.1.2','port':6383},
{'host':'192.168.1.2','port':6384},
{'host':'192.168.1.2','port':6385}
]
try:
redisconn = StrictRedisCluster(startup_nodes=redis_nodes)
except Exception,e:
print "Connect Error!"
sys.exit(1)
redisconn.set('name','admin')
print "name is: ", redisconn.get('name')
redis_cluster()
上一篇: MyEclipse和Eclipse中配置
下一篇: python udp 广播
47863
46424
37314
34758
29331
25989
24945
19966
19563
18049
5806°
6433°
5946°
5975°
7079°
5925°
5963°
6456°
6417°
7798°