Skip to content

Instantly share code, notes, and snippets.

@anhtran
Created July 26, 2023 04:58
Show Gist options
  • Save anhtran/6b71da7222a817ed83071e4b3da4dca7 to your computer and use it in GitHub Desktop.
Save anhtran/6b71da7222a817ed83071e4b3da4dca7 to your computer and use it in GitHub Desktop.
Ví dụ cách sử dụng redis Lock để khóa một tác vụ nào đó trong Python
from redis.lock import Lock
def process_job():
print('worked...')
lock_key = f"lock_save:1234"
lock = Lock(redis_client, lock_key, timeout=3600)
if lock.acquire(blocking=False):
try:
return process_job()
finally:
lock.release()
else:
print('Locked: 1234!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment