Exemple #1
0
 def get_cached_newsfeeds(cls, user_id):
     key = USER_NEWSFEEDS_PATTERN.format(user_id=user_id)
     if GateKeeper.is_switch_on('switch_newsfeed_to_hbase'):
         serializer = HBaseModelSerializer
     else:
         serializer = DjangoModelSerializer
     return RedisHelper.load_objects(key,
                                     lazy_load_newsfeeds(user_id),
                                     serializer=serializer)
Exemple #2
0
    def test_create_new_newsfeed_before_get_cached_newsfeeds(self):
        feed1 = self.create_newsfeed(self.user1, self.create_tweet(self.user1))

        RedisClient.clear()
        conn = RedisClient.get_connection()

        key = USER_NEWSFEEDS_PATTERN.format(user_id=self.user1.id)
        self.assertEqual(conn.exists(key), False)
        feed2 = self.create_newsfeed(self.user1, self.create_tweet(self.user1))
        self.assertEqual(conn.exists(key), True)

        feeds = NewsfeedService.get_cached_newsfeeds(self.user1.id)
        self.assertEqual([f.id for f in feeds], [feed2.id, feed1.id])
 def push_newsfeed_to_cache(cls, newsfeed):
     queryset = NewsFeed.objects.filter(user_id=newsfeed.user_id).order_by('-created_at')
     key = USER_NEWSFEEDS_PATTERN.format(user_id=newsfeed.user_id)
     RedisHelper.push_object(key, newsfeed, queryset)
 def get_cached_newsfeeds(cls, user_id):
     queryset = NewsFeed.objects.filter(user_id=user_id).order_by('-created_at')
     key = USER_NEWSFEEDS_PATTERN.format(user_id=user_id)
     return RedisHelper.load_objects(key, queryset)
Exemple #5
0
 def push_newsfeed_to_cache(cls, newsfeed):
     key = USER_NEWSFEEDS_PATTERN.format(user_id=newsfeed.user_id)
     RedisHelper.push_object(key, newsfeed,
                             lazy_load_newsfeeds(newsfeed.user_id))