标签:sdn sleep 过程 password 服务 redis time 用户 config
redis卸载:后配安装https://blog.csdn.net/isea533/article/details/84550237
key [value, value]
key 代表List的名字, [value, ...] 是值
客户client.py
import random
import threading
import redis
import config
lock = threading.Lock()
lock.acquire()
lock.release()
pool = redis.ConnectionPool(host=config.HOST, port=config.PORT,
decode_responses=True, password=config.PASSWORD)
r = redis.Redis(connection_pool=pool)
# 客户往redis 中放数据
def fun1(redisObj):
value = random.randint(0, 100)
# 往ccc列表中存放
print("开始发送数据:", value)
redisObj.lpush("print",str(value))
for i in range(100):
threading.Thread(target=fun1, args=(r,)).start()
服务器server.py
import redis
import time
import config
pool = redis.ConnectionPool(host=config.HOST, port=config.PORT, decode_responses=True, password=config.PASSWORD)
r = redis.Redis(connection_pool=pool)
# 服务端不断的取
while True:
value = r.brpop("print")
time.sleep(2)
print(value)
方式: 将连接作为一个函数,进行错误捕捉,发生问题的时候重新连接。
import redis
import time
import config
def get_redis():
pool = redis.ConnectionPool(host=config.HOST, port=config.PORT, decode_responses=True, password=config.PASSWORD)
r = redis.Redis(connection_pool=pool)
return r
# 服务端不断的取
r = get_redis()
while True:
try:
value = r.brpop("print")
time.sleep(2)
print(value)
except Exception as e:
print("等待超时重连")
r = get_redis()
标签:sdn sleep 过程 password 服务 redis time 用户 config
原文地址:https://www.cnblogs.com/ShanCe/p/14663870.html