def get_redis(self): """ Only load the redis connection if we use it """ if self._redis is None: self._redis = get_redis_connection() return self._redis
def get_redis(self): ''' Only load the redis connection if we use it ''' if self._redis is None: self._redis = get_redis_connection() return self._redis
def __init__(self, user_id, **kwargs): ''' User id (the user for which we want to read/write notifications) ''' AggregatedFeed.__init__(self, user_id, **kwargs) # location to which we denormalize the count self.format_dict = dict(user_id=user_id) self.count_key = self.count_format % self.format_dict # set the pubsub key if we're using it self.pubsub_key = user_id self.lock_key = self.lock_format % self.format_dict from feedly.storage.redis.connection import get_redis_connection self.redis = get_redis_connection()
def test_zremrangebyrank(self): redis = get_redis_connection() key = "test" # start out fresh redis.delete(key) redis.zadd(key, "a", 1) redis.zadd(key, "b", 2) redis.zadd(key, "c", 3) redis.zadd(key, "d", 4) redis.zadd(key, "e", 5) expected_results = [("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)] results = redis.zrange(key, 0, -1, withscores=True) self.assertEqual(results, expected_results) results = redis.zrange(key, 0, -4, withscores=True) # now the idea is to only keep 3,4,5 max_length = 3 end = (max_length * -1) - 1 redis.zremrangebyrank(key, 0, end) expected_results = [("c", 3.0), ("d", 4.0), ("e", 5.0)] results = redis.zrange(key, 0, -1, withscores=True) self.assertEqual(results, expected_results)
def test_zremrangebyrank(self): redis = get_redis_connection() key = 'test' # start out fresh redis.delete(key) redis.zadd(key, 1, 'a') redis.zadd(key, 2, 'b') redis.zadd(key, 3, 'c') redis.zadd(key, 4, 'd') redis.zadd(key, 5, 'e') expected_results = [('a', 1.0), ('b', 2.0), ('c', 3.0), ( 'd', 4.0), ('e', 5.0)] results = redis.zrange(key, 0, -1, withscores=True) self.assertEqual(results, expected_results) results = redis.zrange(key, 0, -4, withscores=True) # now the idea is to only keep 3,4,5 max_length = 3 end = (max_length * -1) - 1 redis.zremrangebyrank(key, 0, end) expected_results = [('c', 3.0), ('d', 4.0), ('e', 5.0)] results = redis.zrange(key, 0, -1, withscores=True) self.assertEqual(results, expected_results)
def test_zremrangebyrank(self): redis = get_redis_connection() key = 'test' # start out fresh redis.delete(key) redis.zadd(key, 1, 'a') redis.zadd(key, 2, 'b') redis.zadd(key, 3, 'c') redis.zadd(key, 4, 'd') redis.zadd(key, 5, 'e') expected_results = [('a', 1.0), ('b', 2.0), ('c', 3.0), ('d', 4.0), ('e', 5.0)] results = redis.zrange(key, 0, -1, withscores=True) self.assertEqual(results, expected_results) results = redis.zrange(key, 0, -4, withscores=True) # now the idea is to only keep 3,4,5 max_length = 3 end = (max_length * -1) - 1 redis.zremrangebyrank(key, 0, end) expected_results = [('c', 3.0), ('d', 4.0), ('e', 5.0)] results = redis.zrange(key, 0, -1, withscores=True) self.assertEqual(results, expected_results)
def get_batch_interface(self): return get_redis_connection().pipeline(transaction=False)
def get_batch_interface(self): return get_redis_connection().map()