You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thanks a lot @keroxp and @uki00a and all the others for your dedication on this project!
In the documentation you are stating the following:
We recommend to use tx() instead of multi()/exec() for transactional operation. MULTI/EXEC are potentially stateful operation so that operation’s atomicity is guaranteed but redis’s state may change between MULTI and EXEC.
WATCH is designed for these problems. You can ignore it by using TxPipeline because pipelined MULTI/EXEC commands are strictly executed in order at the time and no changes will happen during execution.
From my understanding the following code must be implemented via WATCH:
await redis.watch("key")
const value = JSON.parse(await redis.get("key") as string)
value.someProperty = value.someProperty + 1 // may be a complex operation
await redis.multi()
await redis.set("key", JSON.stringify(value))
const execResult = await redis.exec()
if (!execResult) {
// key was changed, retry entire operation
}
From my understanding, using TxPipeline instead of WATCH + MULTI/EXEC is not possible, because when executing tx.get() I'm not able to retrieve and alter the object within the transaction.
const tx = redisConnection.tx()
const value = JSON.parse(await tx.get("key") as string) // SyntaxError: Unexpected token 'O', "OK" is not valid JSON
Do you agree that using WATCH is required in this case or is there a way to use tx nevertheless?
The text was updated successfully, but these errors were encountered:
I have come to realize that storing JSON directly as a whole string is considered an anti-pattern in Redis. With my WATCH approach I'm solving a concurrency issue but not other disadvantages like efficient value scanning solutions.
Probably will try out RedisJSON together with sendcommand until #372 is resolved.
First of all, thanks a lot @keroxp and @uki00a and all the others for your dedication on this project!
In the documentation you are stating the following:
From my understanding the following code must be implemented via WATCH:
From my understanding, using TxPipeline instead of WATCH + MULTI/EXEC is not possible, because when executing tx.get() I'm not able to retrieve and alter the object within the transaction.
Do you agree that using WATCH is required in this case or is there a way to use tx nevertheless?
The text was updated successfully, but these errors were encountered: