def encode(self, value: EncodableT) -> EncodedT:
        """Return a bytestring or bytes-like representation of the value"""
        if isinstance(value, (bytes, memoryview)):
            return value
        if isinstance(value, bool):
            # special case bool since it is a subclass of int
            raise DataError(
                "Invalid input of type: 'bool'. "
                "Convert to a bytes, string, int or float first."
            )
        if isinstance(value, (int, float)):
            return repr(value).encode()
        if not isinstance(value, str):
            # a value we don't know how to deal with. throw an error
            typename = value.__class__.__name__  # type: ignore[unreachable]
            raise DataError(
                f"Invalid input of type: {typename!r}. "
                "Convert to a bytes, string, int or float first."
            )
        return value.encode(self.encoding, self.encoding_errors)
Return a bytestring or bytes-like representation of the value
aioredis/connection.py