当前位置:首页 > 编程语言 > 正文

python_迁移redis

11-19 编程语言

标签:get   port   password   word   style   根据   import   pass   ons   

一、迁移redis

思路:

  1、获取a redis里面所有的key

  2、判断key的类型:sting、hash

  3、然后根据key的类型set或hset到b redis里

 1 import redis
 2 r = redis.Redis(host = 127.0.0.0,password=HK139bc&*,port=6379,db=0,decode_responses=True)
 3 r1 = redis.Redis(host = 127.0.0.1,password=HK139bc&*,port=6379,db=0,decode_responses=True)
 4 for k in r.keys():
 5     if r.type(k) == string:
 6         value = r.get(k)
 7         r1.set(k,value)
 8     if r.type(k) == hash:
 9         value = r.hgetall(k)
10         r1.hmset(k,value)

 

python_迁移redis

标签:get   port   password   word   style   根据   import   pass   ons   

温馨提示: 本文由杰米博客推荐,转载请保留链接: https://www.jmwww.net/file/biancheng/12158.html