Repository: redis/redis-py
File: redis/commands/core.py (Python)

Code before:
        """
        return self.execute_command("EXPIRETIME", key)

    @experimental_method()
    def digest_local(self, value: Union[bytes, str]) -> Union[bytes, str]:
        """
        Compute the hexadecimal digest of the value locally, without sending it to the server.

        This is useful for conditional operations like IFDEQ/IFDNE where you need to
        compute the digest client-side before sending a command.

        Warning:
        **Experimental** - This API may change or be removed without notice.

        Arguments:
          - value: Union[bytes, str] - the value to compute the digest of.

        Returns:
          - (str | bytes) the XXH3 digest of the value as a hex string (16 hex characters)

        For more information, see https://redis.io/commands/digest
        """
        if not HAS_XXHASH:
            raise NotImplementedError(
                "XXHASH library not installed. Install with: "
                "'pip install xxhash' or 'pip install redis[xxhash]' to use this feature."
            )

        local_digest = xxhash.xxh3_64(value).hexdigest()

        # To align with digest, we want to return bytes if decode_responses is False.
        # The following should work because Python's mixin approach.
        if not self.get_encoder().decode_responses:
            local_digest = local_digest.encode()

        return local_digest

    @experimental_method()
    def digest(self, name: KeyT) -> Union[str, bytes, None]:
        """
        Return the digest of the value stored at the specified key.

        Warning:
        **Experimental** since 7.1.
        This API may change or be removed without notice.
        The API may change based on feedback.

        Arguments:
          - name: KeyT - the key to get the digest of

        Returns:

Review comment (suggestion):
The error message suggests installing with 'pip install redis[xxhash]', but this extra is defined in pyproject.toml and may not be immediately clear to users. Consider adding a note in the error message that this feature requires the xxhash library, and providing both installation options for clarity.
```suggestion
                "XXHASH support requires the optional 'xxhash' library. "
                "Install it with 'pip install xxhash' or use this package's extra with "
                "'pip install redis[xxhash]' to enable this feature."
```

Code after:
        """
        return self.execute_command("EXPIRETIME", key)

    @experimental_method()
    def digest_local(self, value: Union[bytes, str]) -> Union[bytes, str]:
        """
        Compute the hexadecimal digest of the value locally, without sending it to the server.

        This is useful for conditional operations like IFDEQ/IFDNE where you need to
        compute the digest client-side before sending a command.

        Warning:
        **Experimental** - This API may change or be removed without notice.

        Arguments:
          - value: Union[bytes, str] - the value to compute the digest of.
            If a string is provided, it will be encoded using UTF-8 before hashing,
            which matches Redis's default encoding behavior.

        Returns:
          - (str | bytes) the XXH3 digest of the value as a hex string (16 hex characters).
            Returns bytes if decode_responses is False, otherwise returns str.

        For more information, see https://redis.io/commands/digest
        """
        if not HAS_XXHASH:
            raise NotImplementedError(
                "XXHASH support requires the optional 'xxhash' library. "
                "Install it with 'pip install xxhash' or use this package's extra with "
                "'pip install redis[xxhash]' to enable this feature."
            )

        local_digest = xxhash.xxh3_64(value).hexdigest()

        # To align with digest, we want to return bytes if decode_responses is False.
        # The following works because of Python's mixin-based client class hierarchy.
        if not self.get_encoder().decode_responses:
            local_digest = local_digest.encode()

        return local_digest

    @experimental_method()
    def digest(self, name: KeyT) -> Union[str, bytes, None]:
        """
        Return the digest of the value stored at the specified key.

        Warning:
        **Experimental** since 7.1.
        This API may change or be removed without notice.
        The API may change based on feedback.