美文网首页
python3 操作连接redis5.0集群

python3 操作连接redis5.0集群

作者: 小黑佬 | 来源:发表于2020-04-07 16:51 被阅读0次

info

python 3.6
redis 5.0 cluster
centos 7.7

install

pip3 install  redis-py-cluster

demo get redis Cluster keys

from rediscluster import RedisCluster 
from redis._compat import xrange 
startup_nodes = [{"host": "172.16.0.129", "port": "7005"}] 
rc = RedisCluster(startup_nodes=startup_nodes, decode_responses=True, password='123456')
rc.set("foo", "bar") 
print(rc.get("foo")) 
list_keys = rc.keys("app_offline_msg*") 
for kye in list_keys: 
    print(kye) 

#批量设置key
for i in xrange(100):
    d = str(i)
    rc.set(d,d)
    print(rc.get(d))
    rc.incrby(d, 1)

output:


app_offline_msg_1224181518382784513
app_offline_msg_1141219459286798337
app_offline_msg_1170969231404830721
app_offline_msg_1237253025365237761
app_offline_msg_1188790203543576578
app_offline_msg_1165080615504904193
app_offline_msg_1184310738658590721
app_offline_msg_1165530388876840961
app_offline_msg_1237847397003776002
app_offline_msg_1150061722491174913
app_offline_msg_1238128445804019713
app_offline_msg_1158303431055482881
app_offline_msg_1247037518870540289
app_offline_msg_1191290475215945729
app_offline_msg_1247353611901755393
app_offline_msg_1189578220671721473
app_offline_msg_1242303462685589506
app_offline_msg_1172087496336216066
app_offline_msg_1189394020730482690
app_offline_msg_1061218902682742786
app_offline_msg_1243531224310177793
app_offline_msg_1067671227127332865
app_offline_msg_1167275077782028289
app_offline_msg_1236668192376270849
app_offline_msg_1239543302061887490
app_offline_msg_1188024860837511169
app_offline_msg_1188469694559780866
app_offline_msg_1172810205605220353
app_offline_msg_1239178770894323714
app_offline_msg_1202127231797465089
app_offline_msg_1198936165299630081
app_offline_msg_1202712812471492609
app_offline_msg_1240266807971753985
app_offline_msg_1188344386104930305
app_offline_msg_1207351269550469121
app_offline_msg_1207711808237600769
app_offline_msg_1242742417668771841
app_offline_msg_1095187697568882690
app_offline_msg_1239423766847361026
app_offline_msg_1084760738458030081
app_offline_msg_1189038197476024322
app_offline_msg_1158019816198266882
app_offline_msg_1244995629254270978
app_offline_msg_1224209439211126786
app_offline_msg_1235439911169732610
app_offline_msg_1194307772180430849
app_offline_msg_1218539502187634690
app_offline_msg_1167451168732733442
app_offline_msg_1061107157796499458
app_offline_msg_1228551494556192770
app_offline_msg_1241952401793794049
app_offline_msg_1222087041695350786
app_offline_msg_1242104132076359682
app_offline_msg_9991117
app_offline_msg_1221339464078319617
app_offline_msg_1194210628555603969
app_offline_msg_1178565590234492930
app_offline_msg_1234864907604463617
app_offline_msg_1239030787327983618

人生苦短,我用fedora

相关文章

网友评论

      本文标题:python3 操作连接redis5.0集群

      本文链接:https://www.haomeiwen.com/subject/evmnphtx.html