예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
파일: id.py 프로젝트: jordancode/phil
 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]
예제 #4
0
파일: id.py 프로젝트: jordancode/phil
    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]
예제 #5
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
예제 #6
0
파일: lock.py 프로젝트: jordancode/phil
 def get_factory(cls):
     if not cls._factory:
         cls._factory = RedLockFactory([Redis.get_instance("main")])
     return cls._factory
예제 #7
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
예제 #8
0
파일: lock.py 프로젝트: jordancode/phil
 def get_factory(cls):
     if not cls._factory:
         cls._factory = RedLockFactory([Redis.get_instance("main")])
     return cls._factory