def get_next_incr(cls, parent_id, incr_count=1): # redis_key is per user_id redis_key = cls._get_redis_key(parent_id) redis = Redis.get_instance("sort_index") if incr_count != 1: res = redis.incrby(redis_key, incr_count) else: res = redis.incr(redis_key) # increment bits in reverse to maximize space between sort indeces return cls._reverse_bits(res, 32)
def _get_next_increment(self, incr_count=1): if self._shard_id is None or self._pool_id is None or self._interval is None: raise MissingInfoError() # key changes every hour, count starts over redis_key = self._get_redis_key(self._pool_id , self._shard_id , self._interval) redis = Redis.get_instance("id_gen") pipe = redis.pipeline() if incr_count != 1: pipe.incrby(redis_key, incr_count) else: pipe.incr(redis_key) #expire two intervals past the last call so we can handle up to 60 secs of time drift between servers pipe.expire(redis_key, 2 * self.INTERVAL_SECS) res = pipe.execute() return res[0]
def _get_next_increment(self, incr_count=1): if self._shard_id is None or self._pool_id is None or self._interval is None: raise MissingInfoError() # key changes every hour, count starts over redis_key = self._get_redis_key(self._pool_id, self._shard_id, self._interval) redis = Redis.get_instance("id_gen") pipe = redis.pipeline() if incr_count != 1: pipe.incrby(redis_key, incr_count) else: pipe.incr(redis_key) #expire two intervals past the last call so we can handle up to 60 secs of time drift between servers pipe.expire(redis_key, 2 * self.INTERVAL_SECS) res = pipe.execute() return res[0]
def __init__(self, redis=None, queue_name="default"): if redis is None: redis = Redis.get_instance("queue") self.redis = redis self.queue_name = queue_name
def get_factory(cls): if not cls._factory: cls._factory = RedLockFactory([Redis.get_instance("main")]) return cls._factory
def __init__(self, redis = None, queue_name = "default"): if redis is None: redis = Redis.get_instance("queue") self.redis = redis self.queue_name = queue_name