logging.info("finished writting. start reading.") copymp3 = client.get("mp3") logging.info(f"get copy of mp3 size={sys.getsizeof(copymp3)}") with open("a_copy.mp3", mode='wb') as file: # b is important -> binary file.write(copymp3) logging.info("done writing the file.") # Localhost: 20 minisecond to write 3M, 180 miniseconds to SET 5M, 30 miniseconds to GET 5M, 300 minisecond to write 10M; with open("a.pdf", mode='rb') as file: # b is important -> binary fileContent = file.read() pfile = pickle.dumps(fileContent) logging.info( f"size of file={sys.getsizeof(fileContent)}, pickled size={sys.getsizeof(pfile)}" ) client.set("pdf", pfile) logging.info("finished writting. start reading.") pcopymp3 = client.get("pdf") copymp3 = pickle.loads(pcopymp3) logging.info( f"get copy of pdf size={sys.getsizeof(copymp3)}, unpickled from size of {sys.getsizeof(pcopymp3)}" ) with open("a_copy.pdf", mode='wb') as file: # b is important -> binary file.write(copymp3) logging.info("done writing the file from pickled format..") client.set("c", 8.9) print(client.execute("INFO"))
client = Client() print("Start miniredis client.") print(client.info) print( """Available commands:[GET],[SET],[DELETE],[FLUSH],[MGET],[MSET],[LPUSH],[RPUSH],[LPOP],[RPOP],[BLPOP],[BRPOP],[LLEN] [EXPIRE],[TTL],[PERSIST] ([MULTI],[EXEC] to be complete) [INFO],[QUIT],[EXIT]""") while True: command = input(">") segments = command.split(" ") segments[0] = segments[0].upper() if segments[0] == "QUIT" or segments[0] == "EXIT": break arguments = tuple(segments) try: received = client.execute(*arguments) if isinstance(received, bytes): filename = "_".join(segments) + ".bin" with open(filename, mode='wb') as file: # b is important -> binary file.write(received) print(f"{sys.getsizeof(received)} bytes saved as :{filename}") else: print(received) except CommandError as e: print("Wrong error format. Please consult the manual.") except Exception as e: logging.error(e) print(f"Error when executing {command}")