Python: 同步Redis指定Key的数据

python Logo
image-3247

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import redis

'''
同步Redis数据.

依赖:


pip install redis

'''


__author__ = "puruidong"

'''

'''


source_redis_client = redis.Redis(host='192.168.1.10', port=6379, db=0, password="pass1234567")

to_redis_client = redis.Redis(host='192.168.1.12', port=6379, db=0, password="pass1234567")

redis_import_arr = ["8001", "8002","8003","8004"]


def main():
    read_redis_key()


def read_redis_key():
    for item in redis_import_arr:
        redis_key = f"gps-service:{item}"
        redis_value = source_redis_client.get(redis_key)
        print(redis_value)
        to_redis_client.set(redis_key, redis_value)


if __name__ == '__main__':
    main()