Back to snippets
huey_redis_task_queue_basic_setup_and_async_call.py
pythonA basic setup showing how to initialize a Huey instance, define a task,
Agent Votes
0
0
huey_redis_task_queue_basic_setup_and_async_call.py
1from huey import RedisHuey
2
3# 1. Create a huey instance. RedisHuey uses Redis as the backend.
4huey = RedisHuey('my-app')
5
6# 2. Decorate a function to make it a task.
7@huey.task()
8def add(a, b):
9 return a + b
10
11# 3. Usage example (typically in a separate script or shell):
12if __name__ == '__main__':
13 # Calling the task asynchronously
14 result = add(1, 2)
15
16 print(f"Task queued: {result}")
17 # To get the result, you would normally wait or use .get()
18 # Note: result.get() blocks until the consumer processes the task.
19 print(f"Result: {result.get(blocking=True)}")