fix redis cycle and add no reset to daemon
This commit is contained in:
parent
e236e93a79
commit
d43f110a14
|
@ -1,3 +1,4 @@
|
|||
import argparse
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
@ -20,6 +21,12 @@ else:
|
|||
config_path = Path(script_path, 'config', 'config.yml')
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Daemon microservice.')
|
||||
parser.add_argument('--no-reset', action='store_true', help="Don't clear the Redis server databases.")
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.no_reset:
|
||||
Redis().flushall()
|
||||
print('Flushed Redis.')
|
||||
|
||||
|
|
|
@ -9,11 +9,15 @@ def redis_cycle(list_name):
|
|||
:param list_name:
|
||||
:return:
|
||||
"""
|
||||
to_move = redis_cycler_db.rpop(list_name)
|
||||
pipeline = redis_cycler_db.pipeline()
|
||||
pipeline.lpop(list_name)
|
||||
to_move = pipeline.execute()[0]
|
||||
if not to_move:
|
||||
return []
|
||||
redis_cycler_db.lpush(list_name, to_move)
|
||||
new_list = redis_cycler_db.lrange(list_name, 0, -1)
|
||||
pipeline.rpush(list_name, to_move)
|
||||
pipeline.lrange(list_name, 0, -1)
|
||||
results = pipeline.execute()
|
||||
new_list = results[-1]
|
||||
return [x.decode('utf-8') for x in new_list]
|
||||
|
||||
|
||||
|
|
Reference in New Issue