from db.data_generator import DataGenerator from db.redisdb import RedisDB data_generator = DataGenerator() # Generating data data_generator.generate_data() # Retrieving data data = data_generator.get_data() # Create Redis instance redis = RedisDB() redis.set(data) print(redis.get("planes:0")) print(redis.get("planes:1")) # It is not necessary to indicate the "planes" prefix as all of them are "planes" # In order to lock a nested resource use ":"
"host": "localhost", "port": 6379, "db": 0 }, ]) print(f"{bcolors.OKBLUE}## EXECUTING TEST 6 ##{bcolors.ENDC}") print( f"{bcolors.OKBLUE} Several clients, Several locks, one resource, client blocked {bcolors.ENDC}" ) # Get the resource previously to its modification print( f"{bcolors.OKCYAN}Retrieving resource in order to compare it after the update...{bcolors.ENDC}" ) prev_resource = redis.get(RESOURCE_NAME) # Get a lock on the plane number 1 around 10 seconds print(f"{bcolors.OKGREEN}Client 1:{bcolors.ENDC} " f"{bcolors.OKCYAN}Requesting lock on resource '" + RESOURCE_NAME + f"'...{bcolors.ENDC}") plane_lock = dlm.lock(RESOURCE_ID, 10000) # Start the second client process client_2 = threading.Thread(target=thread_function) # Start the second client with the thread print(f"{bcolors.OKGREEN}Client 2: Starting...{bcolors.ENDC} ") client_2.start() # Sleep current thread for 15 seconds in order to simulate it is blocked and check the behaviour
"host": "localhost", "port": 6379, "db": 0 }, ]) print(f"{bcolors.OKBLUE}## EXECUTING TEST 5 ##{bcolors.ENDC}") print( f"{bcolors.OKBLUE} Several clients, Several locks, Different resources {bcolors.ENDC}" ) # Get the resource previously to its modification print(f"{bcolors.OKCYAN}Retrieving resource '" + RESOURCE_1_NAME + f"'in order to compare it after the update..." f"{bcolors.ENDC}") prev_resource_1 = redis.get(RESOURCE_1_NAME) print(f"{bcolors.OKCYAN}Retrieving resource '" + RESOURCE_2_NAME + f"'in order to compare it after the update..." f"{bcolors.ENDC}") prev_resource_2 = redis.get(RESOURCE_2_NAME) # Get a lock on the plane number 1 around 10 seconds print(f"{bcolors.OKGREEN}Client 1:{bcolors.ENDC} " f"{bcolors.OKCYAN}Requesting lock on resource '" + RESOURCE_1_NAME + f"'...{bcolors.ENDC}") plane_0_lock_1 = dlm.lock(RESOURCE_1_ID, 10000) # Start the second client process client_2 = threading.Thread(target=thread_function) # Start the second client with the thread