思路還是挺簡(jiǎn)單的疗杉,以列表或者其他容器作為搭載,將需要傳輸?shù)膮?shù)寫入容器蚕礼,再將這個(gè)容器push到隊(duì)列中烟具。取參數(shù)的時(shí)候?qū)⑷萜骼锏膬?nèi)容對(duì)應(yīng)取出即可,以下為示例代碼:
將參數(shù)push進(jìn)Redis隊(duì)列:
r = redis.Redis(host=REDISHOST, port=REDISPORT, db=REDISDB)
r.rpush("test:items", [param1, param2])
從Redis隊(duì)列拿到參數(shù):
r = redis.Redis(host=config.REDISHOST, port=config.REDISPORT, db=config.REDISDB)
while True:
try:
s, item = r.blpop(["test:items"], timeout=30)
except:
print ('30s內(nèi)沒(méi)有隊(duì)列進(jìn)來(lái)奠蹬,終止程序朝聋。')
break
item = json.loads(item.decode('utf8')
# param1和param2即為容器中要拿到的參數(shù)
param1 = item[0]
param2 = item[1]