lock_key = plane_lock_2.key.decode("utf-8") print(f"{bcolors.OKGREEN}Client 1:{bcolors.ENDC} " f"{bcolors.OKCYAN}Lock key: {bcolors.BOLD}" + lock_key + f"{bcolors.ENDC}") resource_key = redis.get_key(RESOURCE_ID) print(f"{bcolors.WARNING}Redis:{bcolors.ENDC} " f"{bcolors.WARNING}Resource key: {resource_key} {bcolors.ENDC}") # Introduce the lock in the resource print(f"{bcolors.OKGREEN}Client 1:{bcolors.ENDC} " f"{bcolors.OKCYAN}Updating resource '" + RESOURCE_NAME + f"' {bcolors.ENDC}") # Introduce the lock in the resource redis.update(name=RESOURCE_NAME, key="client", value="client_1") redis.update(name=RESOURCE_NAME, key="random", value=random.random()) else: print(f"{bcolors.FAIL}Client 1: Error acquiring the lock on resource '" + RESOURCE_NAME + f"' {bcolors.ENDC}") # Save data changes on db redis.bgsave() # Get the updated resources print(f"{bcolors.OKCYAN}Retrieving updated resource{bcolors.ENDC}") updated_resource = redis.get(RESOURCE_NAME) # Show the resources print(f"{bcolors.OKCYAN}## RESOURCE '" + RESOURCE_NAME + f"' ##{bcolors.ENDC}")
f"' not acquired. {bcolors.ENDC}") lock_1_key = plane_1_lock_1.key.decode("utf-8") print(f"{bcolors.OKGREEN}Client 1 - Lock 1:{bcolors.ENDC} " f"{bcolors.OKCYAN}Lock key: {bcolors.BOLD}" + lock_1_key + f"{bcolors.ENDC}") resource_key = redis.get_key(RESOURCE_ID) print(f"{bcolors.WARNING}Redis:{bcolors.ENDC} " f"{bcolors.WARNING}Resource key: {resource_key} {bcolors.ENDC}") # Introduce the lock in the resource print(f"{bcolors.OKGREEN}Client 1 - Lock 1:{bcolors.ENDC} " f"{bcolors.OKCYAN}Updating resource '" + RESOURCE_NAME + f"' {bcolors.ENDC}") redis.update(name=RESOURCE_NAME, key="updated_by", value="lock_1") redis.update(name=RESOURCE_NAME, key="random", value=random.random()) elif not plane_1_lock_1 and plane_1_lock_2: print(f"{bcolors.OKGREEN}Client 1 - Lock 1:{bcolors.ENDC} " f"{bcolors.FAIL}Lock on resource '" + RESOURCE_NAME + f"' not acquired. {bcolors.ENDC}") print(f"{bcolors.OKGREEN}Client 1 - Lock 2:{bcolors.ENDC} " f"{bcolors.OKCYAN}Lock on resource '" + RESOURCE_NAME + f"' acquired successfully. {bcolors.ENDC}") lock_2_key = plane_1_lock_2.key.decode("utf-8") print(f"{bcolors.OKGREEN}Client 1 - Lock 2:{bcolors.ENDC} " f"{bcolors.OKCYAN}Lock key: {bcolors.BOLD}" + lock_2_key + f"{bcolors.ENDC}")