Beispiel #1
0
    def set(self, key, value):
        """
        Set key to value in redis storage

        :param key: string
        :param value: string
        :return:
        """
        if not self.redis:
            logger.warning_message("{} key didn't save in storage".format(
                key
            ))
            return None

        return self.redis.set(key, value)
Beispiel #2
0
    def get(self, key, default_value=None):
        """
        Get value from redis storage

        :param key: string, redis key for needed value
        :param default_value: string, value that returns if
                              key not found or redis isn't
                              connected to this bot
        :return: value with that key or default value
        """
        # If we had problems with redis connection,
        # return None or other default value
        if not self.redis:
            logger.warning_message("Redis not available for {} key".format(
                key
            ))
            return default_value

        value = self.redis.get(key)
        if value is not None:
            return value
        else:
            return default_value