1 year ago
#384765
tomfumb
WATCH / UNWATCH Redis key outside a transaction
I'm relatively new to Redis and trying to understand how I can use WATCH / UNWATCH to address a concurrency / race condition issue.
All of the documentation I've read describes WATCH in the context of a transaction, but can I WATCH and UNWATCH a key if no transaction occurs?
Here is the scenario:
- I need to modify an object in cache but due to TTL I cannot guarantee that object exists
- I don't want to fetch the object, check it exists, and then call WATCH, because it is possible for TTL to expire between fetching and WATCHing.
- Solution is to WATCH the key, fetch the object, check it exists, and UNWATCH the key if the object doesn't exist
Is this workflow possible, and is there a better way to achieve my goal?
caching
redis
race-condition
0 Answers
Your Answer