Prompt
Redis queue image processing
Latest observation
Oct 24, 2026
OpenAI APIWeb search: off
A common way to do image processing with Redis as a queue is:
- API receives image upload
- Store the image somewhere (disk, S3, etc.)
- Push a job into Redis
- Worker process reads jobs from Redis
- Worker processes the image
- Store processed result
- Return status/result to client
Simple architecture
- Producer: your web app
- Queue: Redis
- Consumer/Worker: background process
- Storage: local file system / S3 / database
Good Redis queue options
1. Simple list-based queue
Use:
LPUSHto enqueueBRPOPto dequeue
Example:
LPUSH image_queue '{"id":123,"path":"/uploads/img1.jpg"}'
Worker:
BRPOP image_queue 0
This is simple, but lacks retries/acknowledgement.
2. More robust: Redis Streams
Better for:
- consumer groups
- retries
- pending jobs tracking
- multiple workers
Use:
XADDto enqueueXREADGROUPto consume
This is usually the better choice for production.
Example workflow
Producer
import redis, json
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
job = {
"job_id": "job_1",
"image_path": "/uploads/input.jpg",
"operation": "resize",
"width": 300,
"height": 300
}
r.xadd("image_jobs", job)
Worker
import redis
from PIL import Image
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
group = "workers"
stream = "image_jobs"
try:
r.xgroup_create(stream, group, id="0", mkstream=True)
except Exception:
pass
while True:
resp = r.xreadgroup(group, "worker-1", {stream: ">"}, count=1, block=5000)
if resp:
_, messages = resp[0]
for message_id, data in messages:
img = Image.open(data["image_path"])
img = img.resize((int(data["width"]), int(data["height"])))
output_path = f"/processed/{data['job_id']}.jpg"
img.save(output_path)
r.xack(stream, group, message_id)
If you want retries
With Streams:
- leave unacked messages in pending
- re-deliver to another worker if needed
- use
XPENDING/XCLAIM
Best practices
- Don’t store raw image binaries in Redis unless they are very small
- Store image files in S3/disk; put only metadata/path in Redis
- Use a unique job ID
- Track job status in Redis or a DB
- Set timeouts and retry logic
- Use worker concurrency if processing is slow
Recommended stack
- Redis Streams
- Python + Celery/RQ or custom worker
- Pillow/OpenCV for image processing
- S3/local storage for images
If you want, I can give you:
- a Python example with Redis Streams,
- a Node.js example, or
- a Dockerized setup for image processing workers.