SPSCommerce / redlock-py

Redis distributed locks in Python
MIT License
572 stars 117 forks source link

Use setex command with older versions of redis #12

Closed markplindsay closed 9 years ago

markplindsay commented 9 years ago

My team's development environment is stuck with Redis 2.2 for now. 2.2 doesn't support the extended nx and px arguments for set, which came along in Redis 2.6. This PR tries using setex as a fallback if the server doesn't recognize those extra args. It will allow me to use redlock-py in development until we all get with the Redis 2.6+ program. Others in the same boat as me may find it useful as well.

optimuspaul commented 9 years ago

This doesn't seem safe. Since acquiring the lock is now two operations and not atomic or locking in their own right we cannot guarantee that two clients didn't ask for the lock at the same time and received it. It's probably safe for development work, but I'm not comfortable pulling it in when it could be used in production.

markplindsay commented 9 years ago

You're right, glad we've got 2.6 in production! Thanks for taking a look.