@@ -48,7 +48,7 @@ Getting Started
48
48
>>> r.set('foo', 'bar')
49
49
True
50
50
>>> r.get('foo')
51
- 'bar'
51
+ b 'bar'
52
52
53
53
By default, all responses are returned as `bytes ` in Python 3 and `str ` in
54
54
Python 2. The user is responsible for decoding to Python 3 strings or Python 2
@@ -406,7 +406,7 @@ Pipelines are quite simple to use:
406
406
>>> # the EXECUTE call sends all buffered commands to the server, returning
407
407
>>> # a list of responses, one for each command.
408
408
>>> pipe.execute()
409
- [True, 'baz']
409
+ [True, b 'baz']
410
410
411
411
For ease of use, all commands being buffered into the pipeline return the
412
412
pipeline object itself. Therefore calls can be chained like:
@@ -534,11 +534,11 @@ instance.
534
534
.. code-block :: pycon
535
535
536
536
>>> p.get_message()
537
- {'pattern': None, 'type': 'subscribe', 'channel': 'my-second-channel', 'data': 1L }
537
+ {'pattern': None, 'type': 'subscribe', 'channel': b 'my-second-channel', 'data': 1 }
538
538
>>> p.get_message()
539
- {'pattern': None, 'type': 'subscribe', 'channel': 'my-first-channel', 'data': 2L }
539
+ {'pattern': None, 'type': 'subscribe', 'channel': b 'my-first-channel', 'data': 2 }
540
540
>>> p.get_message()
541
- {'pattern': None, 'type': 'psubscribe', 'channel': 'my-*', 'data': 3L }
541
+ {'pattern': None, 'type': 'psubscribe', 'channel': b 'my-*', 'data': 3 }
542
542
543
543
Every message read from a `PubSub ` instance will be a dictionary with the
544
544
following keys.
@@ -565,9 +565,9 @@ Let's send a message now.
565
565
>>> r.publish('my-first-channel', 'some data')
566
566
2
567
567
>>> p.get_message()
568
- {'channel': 'my-first-channel', 'data': 'some data', 'pattern': None, 'type': 'message'}
568
+ {'channel': b 'my-first-channel', 'data': b 'some data', 'pattern': None, 'type': 'message'}
569
569
>>> p.get_message()
570
- {'channel': 'my-first-channel', 'data': 'some data', 'pattern': 'my-*', 'type': 'pmessage'}
570
+ {'channel': b 'my-first-channel', 'data': b 'some data', 'pattern': b 'my-*', 'type': 'pmessage'}
571
571
572
572
Unsubscribing works just like subscribing. If no arguments are passed to
573
573
[p]unsubscribe, all channels or patterns will be unsubscribed from.
@@ -577,11 +577,11 @@ Unsubscribing works just like subscribing. If no arguments are passed to
577
577
>>> p.unsubscribe()
578
578
>>> p.punsubscribe('my-*')
579
579
>>> p.get_message()
580
- {'channel': 'my-second-channel', 'data': 2L , 'pattern': None, 'type': 'unsubscribe'}
580
+ {'channel': b 'my-second-channel', 'data': 2 , 'pattern': None, 'type': 'unsubscribe'}
581
581
>>> p.get_message()
582
- {'channel': 'my-first-channel', 'data': 1L , 'pattern': None, 'type': 'unsubscribe'}
582
+ {'channel': b 'my-first-channel', 'data': 1 , 'pattern': None, 'type': 'unsubscribe'}
583
583
>>> p.get_message()
584
- {'channel': 'my-*', 'data': 0L , 'pattern': None, 'type': 'punsubscribe'}
584
+ {'channel': b 'my-*', 'data': 0 , 'pattern': None, 'type': 'punsubscribe'}
585
585
586
586
redis-py also allows you to register callback functions to handle published
587
587
messages. Message handlers take a single argument, the message, which is a
@@ -597,11 +597,11 @@ handled.
597
597
.. code-block :: pycon
598
598
599
599
>>> def my_handler(message):
600
- ... print 'MY HANDLER: ', message['data']
600
+ ... print( 'MY HANDLER: ', message['data'])
601
601
>>> p.subscribe(**{'my-channel': my_handler})
602
602
# read the subscribe confirmation message
603
603
>>> p.get_message()
604
- {'pattern': None, 'type': 'subscribe', 'channel': 'my-channel', 'data': 1L }
604
+ {'pattern': None, 'type': 'subscribe', 'channel': b 'my-channel', 'data': 1 }
605
605
>>> r.publish('my-channel', 'awesome data')
606
606
1
607
607
# for the message handler to work, we need tell the instance to read data.
@@ -611,7 +611,7 @@ handled.
611
611
MY HANDLER: awesome data
612
612
# note here that the my_handler callback printed the string above.
613
613
# `message` is None because the message was handled by our handler.
614
- >>> print message
614
+ >>> print( message)
615
615
None
616
616
617
617
If your application is not interested in the (sometimes noisy)
@@ -628,7 +628,7 @@ application.
628
628
>>> r.publish('my-channel', 'my data')
629
629
1
630
630
>>> p.get_message()
631
- {'channel': 'my-channel', 'data': 'my data', 'pattern': None, 'type': 'message'}
631
+ {'channel': b 'my-channel', 'data': b 'my data', 'pattern': None, 'type': 'message'}
632
632
633
633
There are three different strategies for reading messages.
634
634
@@ -710,11 +710,11 @@ supported:
710
710
.. code-block :: pycon
711
711
712
712
>>> r.pubsub_channels()
713
- ['foo', 'bar']
713
+ [b 'foo', b 'bar']
714
714
>>> r.pubsub_numsub('foo', 'bar')
715
- [('foo', 9001), ('bar', 42)]
715
+ [(b 'foo', 9001), (b 'bar', 42)]
716
716
>>> r.pubsub_numsub('baz')
717
- [('baz', 0)]
717
+ [(b 'baz', 0)]
718
718
>>> r.pubsub_numpat()
719
719
1204
720
720
@@ -835,7 +835,7 @@ operations).
835
835
>>> slave = sentinel.slave_for('mymaster', socket_timeout=0.1)
836
836
>>> master.set('foo', 'bar')
837
837
>>> slave.get('foo')
838
- 'bar'
838
+ b 'bar'
839
839
840
840
The master and slave objects are normal Redis instances with their
841
841
connection pool bound to the Sentinel instance. When a Sentinel backed client
@@ -865,7 +865,7 @@ that return Python iterators for convenience: `scan_iter`, `hscan_iter`,
865
865
>>> for key, value in (('A', '1'), ('B', '2'), ('C', '3')):
866
866
... r.set(key, value)
867
867
>>> for key in r.scan_iter():
868
- ... print key, r.get(key)
868
+ ... print( key, r.get(key) )
869
869
A 1
870
870
B 2
871
871
C 3
0 commit comments