tnm / qr

Queues, stacks, deques, and priority queues with Redis in Python
225 stars 42 forks source link

Race conditions #1

Closed mafr closed 14 years ago

mafr commented 14 years ago

The implementations unfortunately have race conditions since redis doesn't give you transactions. Your length checks won't work reliably if multiple writers push entries into the queue and the queue size limit is reached.

If your writers don't need to notice when the queue is full you can always execute an LTRIM after your push operation. This way your queue will always stay close to the queue's limit.

tnm commented 14 years ago

Thanks, certainly true and known. Original implementation was made to be simple as possible, single-writer. version 0.2.0 will cover multi-writer environments.

twidi commented 14 years ago

Sometimes you don't need to get lenght :

length = redis.llen(key)
all_elements = redis.lrange(key, 0, length)

could be replaced by

all_elements = redis.lrange(key, 0, -1)
tnm commented 14 years ago

twidi: good point. committed.