提交 fa0b0392 编写于 作者: A Abhishek Kumar Singh 提交者: Andy McCurdy

Update README.rst

Fixed `README.rst's` `code-block` directive `lang` name typo.
上级 90532bd2
......@@ -41,7 +41,7 @@ or from source:
Getting Started
---------------
.. code-block:: pycon
.. code-block:: python
>>> import redis
>>> r = redis.Redis(host='localhost', port=6379, db=0)
......@@ -88,7 +88,7 @@ make things easier going forward, it was decided to drop support for these
alternate implementations and instead focus on a single client class.
2.X users that are already using StrictRedis don't have to change the class
name. StrictRedis will continue to work for the forseeable future.
name. StrictRedis will continue to work for the foreseeable future.
2.X users that are using the Redis class will have to make changes if they
use any of the following commands:
......@@ -135,7 +135,7 @@ dict is a mapping of element-names -> score.
MSET, MSETNX and ZADD now look like:
.. code-block:: pycon
.. code-block:: python
def mset(self, mapping):
def msetnx(self, mapping):
......@@ -151,7 +151,7 @@ ZINCRBY
redis-py 2.X accidentally modified the argument order of ZINCRBY, swapping the
order of value and amount. ZINCRBY now looks like:
.. code-block:: pycon
.. code-block:: python
def zincrby(self, name, amount, value):
......@@ -198,7 +198,7 @@ raised where none was before, this might alarm some users.
2.X users should make sure they're wrapping their lock code in a try/catch
like this:
.. code-block:: pycon
.. code-block:: python
try:
with r.lock('my-lock-key', blocking_timeout=5) as lock:
......@@ -248,10 +248,10 @@ a Redis server. By default, each Redis instance you create will in turn create
its own connection pool. You can override this behavior and use an existing
connection pool by passing an already created connection pool instance to the
connection_pool argument of the Redis class. You may choose to do this in order
to implement client side sharding or have finer grain control of how
to implement client side sharding or have fine-grain control of how
connections are managed.
.. code-block:: pycon
.. code-block:: python
>>> pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
>>> r = redis.Redis(connection_pool=pool)
......@@ -268,7 +268,7 @@ argument, which is a string to the unix domain socket file. Additionally, make
sure the unixsocket parameter is defined in your redis.conf file. It's
commented out by default.
.. code-block:: pycon
.. code-block:: python
>>> r = redis.Redis(unix_socket_path='/tmp/redis.sock')
......@@ -279,7 +279,7 @@ a connection pool, passing your class to the connection_class argument.
Other keyword parameters you pass to the pool will be passed to the class
specified during initialization.
.. code-block:: pycon
.. code-block:: python
>>> pool = redis.ConnectionPool(connection_class=YourConnectionClass,
your_arg='...', ...)
......@@ -395,7 +395,7 @@ number of back-and-forth TCP packets between the client and server.
Pipelines are quite simple to use:
.. code-block:: pycon
.. code-block:: python
>>> r = redis.Redis(...)
>>> r.set('bing', 'baz')
......@@ -412,7 +412,7 @@ Pipelines are quite simple to use:
For ease of use, all commands being buffered into the pipeline return the
pipeline object itself. Therefore calls can be chained like:
.. code-block:: pycon
.. code-block:: python
>>> pipe.set('foo', 'bar').sadd('faz', 'baz').incr('auto_number').execute()
[True, True, 6]
......@@ -422,7 +422,7 @@ atomically as a group. This happens by default. If you want to disable the
atomic nature of a pipeline but still want to buffer commands, you can turn
off transactions.
.. code-block:: pycon
.. code-block:: python
>>> pipe = r.pipeline(transaction=False)
......@@ -442,7 +442,7 @@ execution of that transaction, the entire transaction will be canceled and a
WatchError will be raised. To implement our own client-side INCR command, we
could do something like this:
.. code-block:: pycon
.. code-block:: python
>>> with r.pipeline() as pipe:
... while True:
......@@ -475,7 +475,7 @@ Pipeline is used as a context manager (as in the example above) reset()
will be called automatically. Of course you can do this the manual way by
explicitly calling reset():
.. code-block:: pycon
.. code-block:: python
>>> pipe = r.pipeline()
>>> while True:
......@@ -495,7 +495,7 @@ should expect a single parameter, a pipeline object, and any number of keys to
be WATCHed. Our client-side INCR command above can be written like this,
which is much easier to read:
.. code-block:: pycon
.. code-block:: python
>>> def client_side_incr(pipe):
... current_value = pipe.get('OUR-SEQUENCE-KEY')
......@@ -512,7 +512,7 @@ Publish / Subscribe
redis-py includes a `PubSub` object that subscribes to channels and listens
for new messages. Creating a `PubSub` object is easy.
.. code-block:: pycon
.. code-block:: python
>>> r = redis.Redis(...)
>>> p = r.pubsub()
......@@ -520,7 +520,7 @@ for new messages. Creating a `PubSub` object is easy.
Once a `PubSub` instance is created, channels and patterns can be subscribed
to.
.. code-block:: pycon
.. code-block:: python
>>> p.subscribe('my-first-channel', 'my-second-channel', ...)
>>> p.psubscribe('my-*', ...)
......@@ -529,7 +529,7 @@ The `PubSub` instance is now subscribed to those channels/patterns. The
subscription confirmations can be seen by reading messages from the `PubSub`
instance.
.. code-block:: pycon
.. code-block:: python
>>> p.get_message()
{'pattern': None, 'type': 'subscribe', 'channel': 'my-second-channel', 'data': 1L}
......@@ -554,7 +554,7 @@ following keys.
Let's send a message now.
.. code-block:: pycon
.. code-block:: python
# the publish method returns the number matching channel and pattern
# subscriptions. 'my-first-channel' matches both the 'my-first-channel'
......@@ -570,7 +570,7 @@ Let's send a message now.
Unsubscribing works just like subscribing. If no arguments are passed to
[p]unsubscribe, all channels or patterns will be unsubscribed from.
.. code-block:: pycon
.. code-block:: python
>>> p.unsubscribe()
>>> p.punsubscribe('my-*')
......@@ -592,7 +592,7 @@ message dictionary is created and passed to the message handler. In this case,
a `None` value is returned from get_message() since the message was already
handled.
.. code-block:: pycon
.. code-block:: python
>>> def my_handler(message):
... print 'MY HANDLER: ', message['data']
......@@ -618,7 +618,7 @@ subscribe/unsubscribe confirmation messages, you can ignore them by passing
subscribe/unsubscribe messages to be read, but they won't bubble up to your
application.
.. code-block:: pycon
.. code-block:: python
>>> p = r.pubsub(ignore_subscribe_messages=True)
>>> p.subscribe('my-channel')
......@@ -638,7 +638,7 @@ there's no data to be read, `get_message()` will immediately return None. This
makes it trivial to integrate into an existing event loop inside your
application.
.. code-block:: pycon
.. code-block:: python
>>> while True:
>>> message = p.get_message()
......@@ -651,7 +651,7 @@ is a generator that blocks until a message is available. If your application
doesn't need to do anything else but receive and act on messages received from
redis, listen() is an easy way to get up an running.
.. code-block:: pycon
.. code-block:: python
>>> for message in p.listen():
... # do something with the message
......@@ -671,7 +671,7 @@ messages that aren't automatically handled with registered message handlers.
Therefore, redis-py prevents you from calling `run_in_thread()` if you're
subscribed to patterns or channels that don't have message handlers attached.
.. code-block:: pycon
.. code-block:: python
>>> p.subscribe(**{'my-channel': my_handler})
>>> thread = p.run_in_thread(sleep_time=0.001)
......@@ -695,7 +695,7 @@ reconnecting. Messages that were published while the client was disconnected
cannot be delivered. When you're finished with a PubSub object, call its
`.close()` method to shutdown the connection.
.. code-block:: pycon
.. code-block:: python
>>> p = r.pubsub()
>>> ...
......@@ -705,7 +705,7 @@ cannot be delivered. When you're finished with a PubSub object, call its
The PUBSUB set of subcommands CHANNELS, NUMSUB and NUMPAT are also
supported:
.. code-block:: pycon
.. code-block:: python
>>> r.pubsub_channels()
['foo', 'bar']
......@@ -722,7 +722,7 @@ redis-py includes a `Monitor` object that streams every command processed
by the Redis server. Use `listen()` on the `Monitor` object to block
until a command is received.
.. code-block:: pycon
.. code-block:: python
>>> r = redis.Redis(...)
>>> with r.monitor() as m:
......@@ -745,7 +745,7 @@ The following trivial Lua script accepts two parameters: the name of a key and
a multiplier value. The script fetches the value stored in the key, multiplies
it with the multiplier value and returns the result.
.. code-block:: pycon
.. code-block:: python
>>> r = redis.Redis()
>>> lua = """
......@@ -767,7 +767,7 @@ function. Script instances accept the following optional arguments:
Continuing the example from above:
.. code-block:: pycon
.. code-block:: python
>>> r.set('foo', 2)
>>> multiply(keys=['foo'], args=[5])
......@@ -780,7 +780,7 @@ script and returns the result, 10.
Script instances can be executed using a different client instance, even one
that points to a completely different Redis server.
.. code-block:: pycon
.. code-block:: python
>>> r2 = redis.Redis('redis2.example.com')
>>> r2.set('foo', 3)
......@@ -796,7 +796,7 @@ passed as the client argument when calling the script. Care is taken to ensure
that the script is registered in Redis's script cache just prior to pipeline
execution.
.. code-block:: pycon
.. code-block:: python
>>> pipe = r.pipeline()
>>> pipe.set('foo', 5)
......@@ -814,7 +814,7 @@ in order to use redis-py's Sentinel support.
Connecting redis-py to the Sentinel instance(s) is easy. You can use a
Sentinel connection to discover the master and slaves network addresses:
.. code-block:: pycon
.. code-block:: python
>>> from redis.sentinel import Sentinel
>>> sentinel = Sentinel([('localhost', 26379)], socket_timeout=0.1)
......@@ -827,7 +827,7 @@ You can also create Redis client connections from a Sentinel instance. You can
connect to either the master (for write operations) or a slave (for read-only
operations).
.. code-block:: pycon
.. code-block:: python
>>> master = sentinel.master_for('mymaster', socket_timeout=0.1)
>>> slave = sentinel.slave_for('mymaster', socket_timeout=0.1)
......@@ -858,7 +858,7 @@ these commands are fully supported, redis-py also exposes the following methods
that return Python iterators for convenience: `scan_iter`, `hscan_iter`,
`sscan_iter` and `zscan_iter`.
.. code-block:: pycon
.. code-block:: python
>>> for key, value in (('A', '1'), ('B', '2'), ('C', '3')):
... r.set(key, value)
......@@ -880,4 +880,3 @@ Special thanks to:
which some of the socket code is still used.
* Alexander Solovyov for ideas on the generic response callback system.
* Paul Hubbard for initial packaging support.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册