Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable prefix #101

Open
Mogost opened this issue Dec 20, 2022 · 3 comments
Open

Customizable prefix #101

Mogost opened this issue Dec 20, 2022 · 3 comments

Comments

@Mogost
Copy link

Mogost commented Dec 20, 2022

Hi. Faced with something similar to #10

I have shared Redis cache, and control access with ACL.
To separate instances I use prefixes but python-redis-lock overwrites my prefix with lock:

self._name = 'lock:' + name

So I get an access error:

NoPermissionError
this user has no permissions to access one of the keys used as arguments

Could we have a customizable prefix for this case?

@ionelmc
Copy link
Owner

ionelmc commented Dec 21, 2022

You could subclass and do something like:

class PrefixedLock(Lock):
     def __init__(self, redis_client, prefix, name, **kwargs):
        super().__init__(redis_client, name, **kwargs)
        self._name = f'{prefix}:lock:{name}'
        self._signal = f'{prefix}:lock-signal:{name}' 

@Mogost
Copy link
Author

Mogost commented Dec 21, 2022

Yep. But it looks like a dirty solution.
For example in this case I also need to fix this part

local locks = redis.call('keys', 'lock:*')

And it all looks like I want to hack python-redis-lock

@ionelmc
Copy link
Owner

ionelmc commented Dec 21, 2022

Perhaps a key template argument could be added through all the clases/functions. Eg:

Lock(key_template={'lock': 'lock:{}', 'signal': 'lock-signal:{}'})
reset_all(key_template={'lock': 'lock:{}', 'signal': 'lock-signal:{}'})

But I do want to switch to redis functions (redis>=7) for the next release if I get to do one, so there's that...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants