Example #1
0
    def setUp(self):
        self.url = '/api/v1/feed-notifications/'

        self.user = User.objects.get(id=1)
        self.second_user = User.objects.get(id=2)
        self.article1 = Article.objects.get(id=2)
        self.article2 = Article.objects.get(id=3)
        comment1 = Comment.objects.create(content_object=self.article1, text='comment 1')
        comment2 = Comment.objects.create(content_object=self.article2, text='comment 2')

        get_redis_connection().flushdb()
        # Activity 1 and 2 get the same aggregation group.
        self.activity1 = Activity(
            actor=User.objects.get(id=3), verb=CommentVerb, object=comment1,
            target=comment1.content_object, time=datetime.now() - timedelta(minutes=1)
        )
        self.activity2 = Activity(
            actor=User.objects.get(id=3), verb=CommentVerb, object=comment1,
            target=comment1.content_object, time=datetime.now() - timedelta(minutes=2)
        )
        self.activity3 = Activity(
            actor=User.objects.get(id=4), verb=CommentVerb, object=comment2,
            target=comment2.content_object, time=datetime.now()
        )
        feed_manager.add_activity(
            self.activity1,
            [self.user.pk, self.second_user.pk],
            [NotificationFeed]
        )
Example #2
0
 def get_redis(self):
     '''
     Only load the redis connection if we use it
     '''
     if self._redis is None:
         self._redis = get_redis_connection(server_name=self.redis_server)
     return self._redis
Example #3
0
 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
Example #4
0
 def redis(self):
     '''
     Lazy load the redis connection
     '''
     try:
         return self._redis
     except AttributeError:
         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 stream_framework.storage.redis.connection import get_redis_connection
        self.redis = get_redis_connection()
Example #6
0
    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 stream_framework.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, 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)
Example #8
0
    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)
Example #9
0
    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)
Example #11
0
 def get_batch_interface(self):
     return get_redis_connection().pipeline(transaction=False)
Example #12
0
 def get_batch_interface(self):
     return get_redis_connection(
         server_name=self.options.get('redis_server', 'default')).pipeline(
             transaction=False)
Example #13
0
 def get_batch_interface(self):
     return get_redis_connection(
         server_name=self.options.get('redis_server', 'default'),
         redis_settings=self.options.get('STREAM_REDIS_CONFIG'),
     ).pipeline(transaction=False)
 def get_batch_interface(self):
     return get_redis_connection(
         server_name=self.options.get('redis_server', 'default')
     ).pipeline(transaction=False)