Exemplo n.º 1
0
 def set_avatar_for(self, user_id: str, avatar_url: str,
                    app_avatar_url: str, app_avatar_safe_url: str) -> None:
     key = RedisKeys.avatars()
     cache_key = '{}-{}'.format(key, user_id)
     urls = '|'.join([avatar_url, app_avatar_url, app_avatar_safe_url])
     self.cache.set(cache_key, urls, ttl=THIRTY_SECONDS)
     self.redis.hset(key, user_id, urls)
Exemplo n.º 2
0
    def get_avatar_for(self, user_id: str) -> Union[Tuple[str, str, str], None]:
        key = RedisKeys.avatars()
        cache_key = '{}-{}'.format(key, user_id)
        value = self.cache.get(cache_key)
        if value is not None:
            return value.split('|', maxsplit=2)

        value = self.redis.hget(key, user_id)
        if value is None:
            return None

        value = str(value, 'utf-8')
        avatar_url, app_avatar_url, app_avatar_safe_url = value.split('|', maxsplit=2)

        self.cache.set(cache_key, value, ttl=THIRTY_SECONDS)
        return avatar_url, app_avatar_url, app_avatar_safe_url