Skip to content

"bug" about acl_genpass method #3059

Closed
@NC-Cj

Description

@NC-Cj

Thanks for wanting to report an issue you've found in redis-py. Please delete this text and fill in the template below.
It is of course not always possible to reduce your code to a small test case, but it's highly appreciated to have as much data as possible. Thank you!

Version: 5.0.1, "bug" about acl_genpass method

Platform: win11

Description: Refer to the following demo

demo:

from redis import Redis

url = "redis://localhost:6379/1"
rdb = Redis.from_url(url)

print(rdb.acl_genpass(32))

This script is similar to ACL GENPASS [bits], we will get an 8-digit password. But what we got didn't meet expectations.

Your source code might get the desired result this way:

    def acl_genpass(self, bits: Union[int, None] = None, **kwargs) -> ResponseT:
        """Generate a random password value.
        If ``bits`` is supplied then use this number of bits, rounded to
        the next multiple of 4.
        See: https://redis.io/commands/acl-genpass
        """
        pieces = []
        if bits is not None:
            try:
                b = int(bits)
                if b < 0 or b > 4096:
                    raise ValueError
                pieces.append(b)
            except ValueError:
                raise DataError(
                    "genpass optionally accepts a bits argument, between 0 and 4096."
                )
        return self.execute_command("ACL GENPASS", *pieces, **kwargs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions