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

LockError("Cannot release a lock that's no longer owned") #203

Open
RonaldinhoL opened this issue Sep 6, 2021 · 1 comment
Open

LockError("Cannot release a lock that's no longer owned") #203

RonaldinhoL opened this issue Sep 6, 2021 · 1 comment

Comments

@RonaldinhoL
Copy link

RonaldinhoL commented Sep 6, 2021

import asyncio
from aredis import StrictRedis
from aredis.lock import Lock

async def main():
    redis = StrictRedis(host='127.0.0.1', port=6379, db=0, encoding="utf8", decode_responses=True)

    async with Lock(redis=redis, name="XXX", timeout=5, blocking=False):
        redis.hset("aaa", "xxx")

    await asyncio.sleep(0.25)


if __name__ == '__main__':
    asyncio.run(main())
@RonaldinhoL
Copy link
Author

    async def do_release(self, expected_token):
        name = self.name

        async def execute_release(pipe):
            lock_value = await pipe.get(name)
            if lock_value != expected_token:
                raise LockError("Cannot release a lock that's no longer owned")
            await pipe.delete(name)

        await self.redis.transaction(execute_release, name)

seems it is because of lock_value was decode, but expected_token was bytes

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

1 participant