diff --git a/clitools/exports/toRedis.py b/clitools/exports/toRedis.py index b98f2eb..0ccf208 100755 --- a/clitools/exports/toRedis.py +++ b/clitools/exports/toRedis.py @@ -17,10 +17,12 @@ by cocoa ''' from __future__ import print_function -import sys -import os import argparse +import ast +import json +import os import redis +import sys import time argsparser = argparse.ArgumentParser(description="Redis exporter LJ") @@ -44,15 +46,18 @@ r=redis.StrictRedis(host=ip, port=port, db=0) try: while True: - line = sys.stdin.readline() - if line == "": - time.sleep(0.01) - line = line.rstrip('\n') - line=line[1:-1] - line = line.replace("[",'(') - line = line.replace("]",')') - line = "[{}]".format(line) - if r.set(key,line)==True: + line = sys.stdin.readline() + if line == "": + time.sleep(0.01) + line = line.rstrip('\n') + line=line[1:-1] + # Decode as list of lists + pointsList = ast.literal_eval(line) + # convert to list of tuples + pointsList = [tuple(elem) for elem in pointsList] + # Convert to JSON string + line = json.dumps( pointsList ) + if r.set(key,line)==True: debug("exports::redis set("+str(key)+") to "+line) except EOFError: debug("break")# no more information diff --git a/clitools/generators/fromRedis.py b/clitools/generators/fromRedis.py index 7e127d3..31d9da2 100755 --- a/clitools/generators/fromRedis.py +++ b/clitools/generators/fromRedis.py @@ -64,6 +64,7 @@ while True: # Convert to JSON string line = json.dumps( pointsList ) debug(name,"Key:{} line:{}".format(key,line)) + # Output print(line, flush=True); looptime = time.time() - start if( looptime < optimal_looptime ):