I used Only Redis as my DB, and my client is ServiceStack.Redis. The thing is, if two concurrent request need to update one key, then it can be a race condition. For example
A:
B:
if the origin "key" is 1000. If speration A and B are serialized, the right results of this two operations of "key" will be 800. But if A and B happens in the same time. Before A can commit, Operation B get value 1000 from "key", and set 900 to "key". That's not what I want. How can I prevent this kind of race conditions, use "WATCH"?
You should read the docs on Transactions in Redis, transactions in Redis is essentially batching multiple operations so they're executed as a single atomic operation.
Since it's only batching operations, you cannot perform any reads within the context of a transaction. Any reads you need before hand need to be retrieved before the start of the transaction. You can then use the Redis WATCH to watch for any keys that shouldn't be modified before your transaction completes, if a key was modified the transaction will fail and no operations will be processed.