if not self._value:
            return "*"
        return self.OPERATOR_MAP[self._operator] % (
            self._field,
            self._formatted_tag_value,
        )
[docs]class RedisNum(RedisFilterField):
    """A RedisFilterField representing a numeric field in a Redis index."""
    OPERATORS: Dict[RedisFilterOperator, str] = {
        RedisFilterOperator.EQ: "==",
        RedisFilterOperator.NE: "!=",
        RedisFilterOperator.LT: "<",
        RedisFilterOperator.GT: ">",
        RedisFilterOperator.LE: "<=",
        RedisFilterOperator.GE: ">=",
    }
    OPERATOR_MAP: Dict[RedisFilterOperator, str] = {
        RedisFilterOperator.EQ: "@%s:[%s %s]",
        RedisFilterOperator.NE: "(-@%s:[%s %s])",
        RedisFilterOperator.GT: "@%s:[(%s +inf]",
        RedisFilterOperator.LT: "@%s:[-inf (%s]",
        RedisFilterOperator.GE: "@%s:[%s +inf]",
        RedisFilterOperator.LE: "@%s:[-inf %s]",
    }
    SUPPORTED_VAL_TYPES = (int, float, type(None))
    def __str__(self) -> str:
        """Return the query syntax for a RedisNum filter expression."""
        if self._value is None:
            return "*"
        if (
            self._operator == RedisFilterOperator.EQ
            or self._operator == RedisFilterOperator.NE
        ):
            return self.OPERATOR_MAP[self._operator] % (
                self._field,
                self._value,
                self._value,
            )
        else: