예제 #1
0
    def get_channels_with_sort(self):
        key = RedisKeys.channels_with_sort()
        channels = self.cache.get(key)
        if channels is not None:
            return channels

        raw_channels = self.redis.hgetall(key)
        clean_channels = dict()

        if raw_channels is None or len(raw_channels) == 0:
            return None

        for channel_id, channel_sort_channel_name in raw_channels.items():
            try:
                channel_sort_channel_name = str(channel_sort_channel_name,
                                                'utf8')
                channel_sort, channel_tags, channel_name = channel_sort_channel_name.split(
                    '|', maxsplit=2)
                channel_sort = int(channel_sort)
                channel_id = str(channel_id, 'utf8')

                if channel_tags == 'None':
                    channel_tags = ''

                clean_channels[channel_id] = (channel_name, channel_sort,
                                              channel_tags)
            except Exception as e:
                logger.error(
                    'invalid channel name in redis with key {}, value was "{}": {}'
                    .format(key, channel_sort_channel_name, str(e)))

        self.cache.set(key, clean_channels, ttl=ONE_MINUTE)
        return clean_channels
예제 #2
0
파일: redis.py 프로젝트: labrook/dino
    def set_channels_with_sort(self, channels):
        if len(channels) == 0:
            return

        key = RedisKeys.channels_with_sort()
        self.cache.set(key, channels, ttl=ONE_MINUTE)

        redis_channels = dict()
        for channel_id, (channel_name, channel_sort, tags) in channels.items():
            redis_channels[channel_id] = '{}|{}|{}'.format(str(channel_sort), tags, channel_name)

        self.redis.hmset(key, redis_channels)
        self.redis.expire(key, ONE_MINUTE)
예제 #3
0
 def reset_channels_with_sort(self):
     key = RedisKeys.channels_with_sort()
     self.cache.delete(key)
     self.redis.delete(key)
예제 #4
0
파일: redis.py 프로젝트: rbarrette/dino
 def set_channels_with_sort(self, channels):
     key = RedisKeys.channels_with_sort()
     self.cache.set(key, channels, ttl=TEN_MINUTES)
예제 #5
0
파일: redis.py 프로젝트: rbarrette/dino
 def get_channels_with_sort(self):
     key = RedisKeys.channels_with_sort()
     return self.cache.get(key)