Skip to content

Instantly share code, notes, and snippets.

@lqez
Created April 14, 2015 11:44
Show Gist options
  • Save lqez/662ab06a230dffc6c142 to your computer and use it in GitHub Desktop.
Save lqez/662ab06a230dffc6c142 to your computer and use it in GitHub Desktop.
import redis
r = redis.StrictRedis(host='localhost')
r.delete('queue')
# Add work into queue
print r.hset('queue', 'file1.mp4', 'will be processed on machine A')
# return value will be 1 - a new value
# Another machine tries to add same work
print r.hset('queue', 'file1.mp4', 'will be processed on machine B')
# return value will be 0 - duplicated
# Then, tries to add other work
print r.hset('queue', 'file2.mp4', 'will be processed on machine B')
# return value will be 1 - a new value
# Machine A finished file1.mp4
print r.hdel('queue', 'file1.mp4')
# return value will be 1 - deleted
# Get all jobs from queue
print r.hgetall('queue')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment