@@ -20,8 +20,7 @@ There are two types of batch that you can use:
20
20
21
21
- ** Pipelines** avoid network and processing overhead by sending several commands
22
22
to the server together in a single communication. The server then sends back
23
- a single communication with all the responses. This typically improves
24
- performance compared to sending the commands separately. See the
23
+ a single communication with all the responses. See the
25
24
[ Pipelining] ({{< relref "/develop/use/pipelining" >}}) page for more
26
25
information.
27
26
- ** Transactions** guarantee that all the included commands will execute
@@ -80,31 +79,11 @@ pipe = r.pipeline(transaction=False)
80
79
81
80
## Watch keys for changes
82
81
83
- When you use transactions, you will often need to read values from the
84
- database, process them, and then write the modified values back. Ideally,
85
- you would want to perform the whole read-modify-write sequence atomically, without any
86
- interruptions from other clients. However, you don't get the results from
87
- any commands that are buffered in a transaction until the whole transaction has finished
88
- executing. This means you can't read keys, process the data, and then write the keys back
89
- in the same transaction. Other clients can therefore modify the values you have
90
- read before you have the chance to write them.
91
-
92
- Redis solves this problem by letting you watch for changes to keys in the
93
- database just before executing a transaction. The basic stages are as
94
- follows:
95
-
96
- 1 . Start watching the keys you are about to update.
97
- 1 . Read the data values from those keys.
98
- 1 . Perform changes to the data values.
99
- 1 . Add commands to a transaction to write the data values back.
100
- 1 . Attempt to execute the transaction.
101
- 1 . If the keys you were watching changed before the transaction started
102
- executing, then abort the transaction and start again from step 1.
103
- Otherwise, the transaction was successful and the updated data is written back.
104
-
105
- This technique is called * optimistic locking* and works well in cases
106
- where multiple clients might access the same data simultaneously, but
107
- usually don't. See
82
+ Redis supports * optimistic locking* to avoid inconsistent updates
83
+ to different keys. The basic idea is to watch for changes to any
84
+ keys that you use in a transaction while you are are processing the
85
+ updates. If the watched keys do change, you must restart the updates
86
+ with the latest data from the keys. See
108
87
[ Transactions] ({{< relref "/develop/interact/transactions" >}})
109
88
for more information about optimistic locking.
110
89
0 commit comments