redis集群
cd /usr/local/redis3.0/src
./redis-trib.rb create --replicas 1 ip1:7000 ip1:7001
cluster info/nodes
redis-cli -c -h yourhost -p yourpost
https://github.com/andymccurdy/redis-py
pip install redis-py-cluster
pip升级pip-9.0.1.tar.gz
# !/usr/bin/env python
# coding:utf-8
# import redis
from rediscluster import StrictRedisCluster
import sys
redis_nodes = [{‘host‘:‘ip1‘,‘port‘:7000}]
try:
redisconn = StrictRedisCluster(startup_nodes=redis_nodes)
except Exception,e:
print "Connect Error!"
sys.exit(1)
redisconn.set(‘name‘, ‘admin‘)
redisconn.set(‘age‘, 18)
print "name is: ", redisconn.get(‘name‘)
print "age is: ", redisconn.get(‘age‘)
(11) 在你的计算机安装Redis 服务器和Python 的redis 库(pip install redis)。创建一
个Redis 的哈希表test,包含字段count(1) 和name(‘Fester Bestertester‘),输出test 的所有字段。
# redisconn.hmset(‘test‘, {‘count‘: 1, ‘name‘: ‘Fester Bestertester‘})
print redisconn.hgetall(‘test‘)
(12) 自增test 的count 字段并输出它。
>>> conn.hincrby(‘test‘, ‘count‘, 3)
4
>>> conn.hget(‘test‘, ‘count‘)
b‘4‘
本文出自 “python 运维” 博客,谢绝转载!