Skip to content

Commit 76eebce

Browse files
authored
Use pycon lexer to highlight code Python console code blocks (#1327)
The lexer is documented at: https://pygments.org/docs/lexers/#pygments.lexers.python.PythonConsoleLexer It is the preferred lexer for the Python console and its output.
1 parent 3261a05 commit 76eebce

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

README.rst

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ or from source:
4141
Getting Started
4242
---------------
4343

44-
.. code-block:: python
44+
.. code-block:: pycon
4545
4646
>>> import redis
4747
>>> r = redis.Redis(host='localhost', port=6379, db=0)
@@ -250,7 +250,7 @@ connection_pool argument of the Redis class. You may choose to do this in order
250250
to implement client side sharding or have fine-grain control of how
251251
connections are managed.
252252

253-
.. code-block:: python
253+
.. code-block:: pycon
254254
255255
>>> pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
256256
>>> r = redis.Redis(connection_pool=pool)
@@ -267,7 +267,7 @@ argument, which is a string to the unix domain socket file. Additionally, make
267267
sure the unixsocket parameter is defined in your redis.conf file. It's
268268
commented out by default.
269269

270-
.. code-block:: python
270+
.. code-block:: pycon
271271
272272
>>> r = redis.Redis(unix_socket_path='/tmp/redis.sock')
273273
@@ -278,7 +278,7 @@ a connection pool, passing your class to the connection_class argument.
278278
Other keyword parameters you pass to the pool will be passed to the class
279279
specified during initialization.
280280

281-
.. code-block:: python
281+
.. code-block:: pycon
282282
283283
>>> pool = redis.ConnectionPool(connection_class=YourConnectionClass,
284284
your_arg='...', ...)
@@ -394,7 +394,7 @@ number of back-and-forth TCP packets between the client and server.
394394

395395
Pipelines are quite simple to use:
396396

397-
.. code-block:: python
397+
.. code-block:: pycon
398398
399399
>>> r = redis.Redis(...)
400400
>>> r.set('bing', 'baz')
@@ -411,7 +411,7 @@ Pipelines are quite simple to use:
411411
For ease of use, all commands being buffered into the pipeline return the
412412
pipeline object itself. Therefore calls can be chained like:
413413

414-
.. code-block:: python
414+
.. code-block:: pycon
415415
416416
>>> pipe.set('foo', 'bar').sadd('faz', 'baz').incr('auto_number').execute()
417417
[True, True, 6]
@@ -421,7 +421,7 @@ atomically as a group. This happens by default. If you want to disable the
421421
atomic nature of a pipeline but still want to buffer commands, you can turn
422422
off transactions.
423423

424-
.. code-block:: python
424+
.. code-block:: pycon
425425
426426
>>> pipe = r.pipeline(transaction=False)
427427
@@ -441,7 +441,7 @@ execution of that transaction, the entire transaction will be canceled and a
441441
WatchError will be raised. To implement our own client-side INCR command, we
442442
could do something like this:
443443

444-
.. code-block:: python
444+
.. code-block:: pycon
445445
446446
>>> with r.pipeline() as pipe:
447447
... while True:
@@ -474,7 +474,7 @@ Pipeline is used as a context manager (as in the example above) reset()
474474
will be called automatically. Of course you can do this the manual way by
475475
explicitly calling reset():
476476

477-
.. code-block:: python
477+
.. code-block:: pycon
478478
479479
>>> pipe = r.pipeline()
480480
>>> while True:
@@ -494,7 +494,7 @@ should expect a single parameter, a pipeline object, and any number of keys to
494494
be WATCHed. Our client-side INCR command above can be written like this,
495495
which is much easier to read:
496496

497-
.. code-block:: python
497+
.. code-block:: pycon
498498
499499
>>> def client_side_incr(pipe):
500500
... current_value = pipe.get('OUR-SEQUENCE-KEY')
@@ -514,15 +514,15 @@ Publish / Subscribe
514514
redis-py includes a `PubSub` object that subscribes to channels and listens
515515
for new messages. Creating a `PubSub` object is easy.
516516

517-
.. code-block:: python
517+
.. code-block:: pycon
518518
519519
>>> r = redis.Redis(...)
520520
>>> p = r.pubsub()
521521
522522
Once a `PubSub` instance is created, channels and patterns can be subscribed
523523
to.
524524

525-
.. code-block:: python
525+
.. code-block:: pycon
526526
527527
>>> p.subscribe('my-first-channel', 'my-second-channel', ...)
528528
>>> p.psubscribe('my-*', ...)
@@ -531,7 +531,7 @@ The `PubSub` instance is now subscribed to those channels/patterns. The
531531
subscription confirmations can be seen by reading messages from the `PubSub`
532532
instance.
533533

534-
.. code-block:: python
534+
.. code-block:: pycon
535535
536536
>>> p.get_message()
537537
{'pattern': None, 'type': 'subscribe', 'channel': 'my-second-channel', 'data': 1L}
@@ -556,7 +556,7 @@ following keys.
556556

557557
Let's send a message now.
558558

559-
.. code-block:: python
559+
.. code-block:: pycon
560560
561561
# the publish method returns the number matching channel and pattern
562562
# subscriptions. 'my-first-channel' matches both the 'my-first-channel'
@@ -572,7 +572,7 @@ Let's send a message now.
572572
Unsubscribing works just like subscribing. If no arguments are passed to
573573
[p]unsubscribe, all channels or patterns will be unsubscribed from.
574574

575-
.. code-block:: python
575+
.. code-block:: pycon
576576
577577
>>> p.unsubscribe()
578578
>>> p.punsubscribe('my-*')
@@ -594,7 +594,7 @@ message dictionary is created and passed to the message handler. In this case,
594594
a `None` value is returned from get_message() since the message was already
595595
handled.
596596

597-
.. code-block:: python
597+
.. code-block:: pycon
598598
599599
>>> def my_handler(message):
600600
... print 'MY HANDLER: ', message['data']
@@ -620,7 +620,7 @@ subscribe/unsubscribe confirmation messages, you can ignore them by passing
620620
subscribe/unsubscribe messages to be read, but they won't bubble up to your
621621
application.
622622

623-
.. code-block:: python
623+
.. code-block:: pycon
624624
625625
>>> p = r.pubsub(ignore_subscribe_messages=True)
626626
>>> p.subscribe('my-channel')
@@ -640,7 +640,7 @@ there's no data to be read, `get_message()` will immediately return None. This
640640
makes it trivial to integrate into an existing event loop inside your
641641
application.
642642

643-
.. code-block:: python
643+
.. code-block:: pycon
644644
645645
>>> while True:
646646
>>> message = p.get_message()
@@ -653,7 +653,7 @@ is a generator that blocks until a message is available. If your application
653653
doesn't need to do anything else but receive and act on messages received from
654654
redis, listen() is an easy way to get up an running.
655655

656-
.. code-block:: python
656+
.. code-block:: pycon
657657
658658
>>> for message in p.listen():
659659
... # do something with the message
@@ -673,7 +673,7 @@ messages that aren't automatically handled with registered message handlers.
673673
Therefore, redis-py prevents you from calling `run_in_thread()` if you're
674674
subscribed to patterns or channels that don't have message handlers attached.
675675

676-
.. code-block:: python
676+
.. code-block:: pycon
677677
678678
>>> p.subscribe(**{'my-channel': my_handler})
679679
>>> thread = p.run_in_thread(sleep_time=0.001)
@@ -697,7 +697,7 @@ reconnecting. Messages that were published while the client was disconnected
697697
cannot be delivered. When you're finished with a PubSub object, call its
698698
`.close()` method to shutdown the connection.
699699

700-
.. code-block:: python
700+
.. code-block:: pycon
701701
702702
>>> p = r.pubsub()
703703
>>> ...
@@ -707,7 +707,7 @@ cannot be delivered. When you're finished with a PubSub object, call its
707707
The PUBSUB set of subcommands CHANNELS, NUMSUB and NUMPAT are also
708708
supported:
709709

710-
.. code-block:: python
710+
.. code-block:: pycon
711711
712712
>>> r.pubsub_channels()
713713
['foo', 'bar']
@@ -724,7 +724,7 @@ redis-py includes a `Monitor` object that streams every command processed
724724
by the Redis server. Use `listen()` on the `Monitor` object to block
725725
until a command is received.
726726

727-
.. code-block:: python
727+
.. code-block:: pycon
728728
729729
>>> r = redis.Redis(...)
730730
>>> with r.monitor() as m:
@@ -747,7 +747,7 @@ The following trivial Lua script accepts two parameters: the name of a key and
747747
a multiplier value. The script fetches the value stored in the key, multiplies
748748
it with the multiplier value and returns the result.
749749

750-
.. code-block:: python
750+
.. code-block:: pycon
751751
752752
>>> r = redis.Redis()
753753
>>> lua = """
@@ -769,7 +769,7 @@ function. Script instances accept the following optional arguments:
769769

770770
Continuing the example from above:
771771

772-
.. code-block:: python
772+
.. code-block:: pycon
773773
774774
>>> r.set('foo', 2)
775775
>>> multiply(keys=['foo'], args=[5])
@@ -782,7 +782,7 @@ script and returns the result, 10.
782782
Script instances can be executed using a different client instance, even one
783783
that points to a completely different Redis server.
784784

785-
.. code-block:: python
785+
.. code-block:: pycon
786786
787787
>>> r2 = redis.Redis('redis2.example.com')
788788
>>> r2.set('foo', 3)
@@ -798,7 +798,7 @@ passed as the client argument when calling the script. Care is taken to ensure
798798
that the script is registered in Redis's script cache just prior to pipeline
799799
execution.
800800

801-
.. code-block:: python
801+
.. code-block:: pycon
802802
803803
>>> pipe = r.pipeline()
804804
>>> pipe.set('foo', 5)
@@ -816,7 +816,7 @@ in order to use redis-py's Sentinel support.
816816
Connecting redis-py to the Sentinel instance(s) is easy. You can use a
817817
Sentinel connection to discover the master and slaves network addresses:
818818

819-
.. code-block:: python
819+
.. code-block:: pycon
820820
821821
>>> from redis.sentinel import Sentinel
822822
>>> sentinel = Sentinel([('localhost', 26379)], socket_timeout=0.1)
@@ -829,7 +829,7 @@ You can also create Redis client connections from a Sentinel instance. You can
829829
connect to either the master (for write operations) or a slave (for read-only
830830
operations).
831831

832-
.. code-block:: python
832+
.. code-block:: pycon
833833
834834
>>> master = sentinel.master_for('mymaster', socket_timeout=0.1)
835835
>>> slave = sentinel.slave_for('mymaster', socket_timeout=0.1)
@@ -860,7 +860,7 @@ these commands are fully supported, redis-py also exposes the following methods
860860
that return Python iterators for convenience: `scan_iter`, `hscan_iter`,
861861
`sscan_iter` and `zscan_iter`.
862862

863-
.. code-block:: python
863+
.. code-block:: pycon
864864
865865
>>> for key, value in (('A', '1'), ('B', '2'), ('C', '3')):
866866
... r.set(key, value)

0 commit comments

Comments
 (0)