1
- Advanced Features
1
+ from redis import RedisClusterAdvanced Features
2
2
=================
3
3
4
4
A note about threading
@@ -167,6 +167,7 @@ the server.
167
167
168
168
.. code :: python
169
169
170
+ >> > rc = RedisCluster()
170
171
>> > with rc.pipeline() as pipe:
171
172
... pipe.set(' foo' , ' value1' )
172
173
... pipe.set(' bar' , ' value2' )
@@ -208,7 +209,7 @@ embedding them within a pipeline would eventually get ‘AttributeError’.
208
209
With this approach, if the application uses ‘client.pipeline(transaction=True)’,
209
210
then switching the client with a cluster-aware instance would simplify
210
211
code changes (to some extent). This may be true for application code that
211
- makes use of hash keys, since its transactions may are already be
212
+ makes use of hash keys, since its transactions may already be
212
213
mapping all commands to the same slot.
213
214
214
215
An alternative is some kind of two-step commit solution, where a slot
@@ -220,14 +221,14 @@ transactional mode. To enable transactional context set:
220
221
221
222
.. code :: python
222
223
223
- >> > p = r .pipeline(transaction = True )
224
+ >> > p = rc .pipeline(transaction = True )
224
225
225
226
After entering the transactional context you can add commands to a transactional
226
227
context, by one of the following ways:
227
228
228
229
.. code :: python
229
230
230
- >> > p = r .pipeline(transaction = True ) # Chaining commands
231
+ >> > p = rc .pipeline(transaction = True ) # Chaining commands
231
232
>> > p.set(" key" , " value" )
232
233
>> > p.get(" key" )
233
234
>> > response = p.execute()
236
237
237
238
.. code :: python
238
239
239
- >> > with r .pipeline(transaction = True ) as pipe: # Using context manager
240
+ >> > with rc .pipeline(transaction = True ) as pipe: # Using context manager
240
241
... pipe.set(" key" , " value" )
241
242
... pipe.get(" key" )
242
243
... response = pipe.execute()
@@ -251,7 +252,7 @@ More information `here <https://redis.io/docs/latest/operate/oss_and_stack/refer
251
252
252
253
.. code :: python
253
254
254
- >> > with r .pipeline(transaction = True ) as pipe:
255
+ >> > with rc .pipeline(transaction = True ) as pipe:
255
256
... pipe.set(" {tag} foo" , " bar" )
256
257
... pipe.set(" {tag} bar" , " foo" )
257
258
... pipe.get(" {tag} foo" )
@@ -273,7 +274,7 @@ transaction execution.
273
274
274
275
.. code :: python
275
276
276
- >> > with r .pipeline(transaction = True ) as pipe:
277
+ >> > with rc .pipeline(transaction = True ) as pipe:
277
278
... pipe.watch(" mykey" ) # Apply locking by immediately executing command
278
279
... val = pipe.get(" mykey" ) # Immediately retrieves value
279
280
... val = val + 1 # Increment value
0 commit comments