Skip to content

Instantly share code, notes, and snippets.

@elegantcoder
Created July 30, 2018 12:27
Show Gist options
  • Save elegantcoder/bc3132424b0eb9a04e42cb6c037f75bb to your computer and use it in GitHub Desktop.
Save elegantcoder/bc3132424b0eb9a04e42cb6c037f75bb to your computer and use it in GitHub Desktop.
Sidekiq.py
from redis import Redis
import simplejson
import os
class Sidekiq(object):
"""Dirt simple Sidekiq client in Python. Can be used to create jobs."""
def __init__(self):
host = os.environ['SIDEKIQ_REDIS_HOST']
port = os.environ['SIDEKIQ_REDIS_PORT']
db = os.environ['SIDEKIQ_REDIS_DB']
self.redis = Redis(host=host, port=int(port), db=int(db))
def push(self, queue, object):
key = "queue:%s" % queue
self.redis.lpush(key, simplejson.dumps(object))
def pop(self, queue):
key = "queue:%s" % queue
return simplejson.loads(self.redis.pop(key))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment