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

Redlock does not implement / respect namespace #520

Closed
smlbiobot opened this issue Nov 22, 2020 · 2 comments
Closed

Redlock does not implement / respect namespace #520

smlbiobot opened this issue Nov 22, 2020 · 2 comments

Comments

@smlbiobot
Copy link

I am using trying to use the aiocache.lock.RedLock which comes with your library, but it has issues with a namespace is set. As namespace is get/set on the cache itself, this lock has issue fetching the key when the namespace is set. (The actual key has a different value depending on whether a namespace is set.

For example, by inserting namespace in your example:

from aiocache import Cache
from aiocache.lock import RedLock

namespace = "foo"

cache = Cache(Cache.REDIS)
async with RedLock(cache, 'key', lease=1):  # Calls will wait here
    result = await cache.get('key', namespace=namespace)
    if result is not None:
        return result
    result = await super_expensive_function()
    await cache.set('key', result, namespace=namespace)

It will run into errors when namespace is not None. I have tried to manually insert the namespace into the key used in lock but then the two keys don’t match and the lock throws an error. The only way I see that you can get around this is by allowing namespace to be be a kwargs for RedLock.

Alternatively, how do you envision that locks are implemented using your library?

Thanks!

@Dreamsorcerer
Copy link
Member

If you can create a PR with a test and a fix, then we can get this resolved. Adding a namespace parameter sounds reasonable.

@padraic-shafer
Copy link
Contributor

This should now be fixed by #627.

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

3 participants