发布时间:2019-09-07 08:08:10编辑:auto阅读(1636)
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 广播
48914
48005
38776
35910
30330
27103
26115
20948
20772
19128
634°
713°
683°
682°
654°
622°
716°
771°
907°
1092°