



redis-py 2.10.5 documentation

 [redis-py](#) 

 3.5.3

 

[redis-py](#)

* »

* redis-py 2.10.5 documentation

* [Edit on GitHub](https://github.com/redis/redis-py/blob/3.5.3/docs/index)

---

Welcome to redis-py’s documentation![¶](#welcome-to-redis-py-s-documentation "Permalink to this headline")

==========================================================================================================

Indices and tables[¶](#indices-and-tables "Permalink to this headline")

-----------------------------------------------------------------------

* [Index](genindex.html)

* [Module Index](py-modindex.html)

* [Search Page](search.html)

Contents:[¶](#contents "Permalink to this headline")

----------------------------------------------------

*exception* redis.AuthenticationError[[source]](_modules/redis/exceptions.html#AuthenticationError)[¶](#redis.AuthenticationError "Permalink to this definition")

*exception* redis.AuthenticationWrongNumberOfArgsError[[source]](_modules/redis/exceptions.html#AuthenticationWrongNumberOfArgsError)[¶](#redis.AuthenticationWrongNumberOfArgsError "Permalink to this definition")

An error to indicate that the wrong number of args

were sent to the AUTH command

*class* redis.BlockingConnectionPool(*max\_connections=50*, *timeout=20*, *connection\_class=<class 'redis.connection.Connection'>*, *queue\_class=<class 'queue.LifoQueue'>*, *\*\*connection\_kwargs*)[[source]](_modules/redis/connection.html#BlockingConnectionPool)[¶](#redis.BlockingConnectionPool "Permalink to this definition")

Thread-safe blocking connection pool:

```

>>> from redis.client import Redis

>>> client = Redis(connection\_pool=BlockingConnectionPool())

```

It performs the same function as the default

`:py:class: ~redis.connection.ConnectionPool` implementation, in that,

it maintains a pool of reusable connections that can be shared by

multiple redis clients (safely across threads if required).

The difference is that, in the event that a client tries to get a

connection from the pool when all of connections are in use, rather than

raising a `:py:class: ~redis.exceptions.ConnectionError` (as the default

`:py:class: ~redis.connection.ConnectionPool` implementation does), it

makes the client wait (“blocks”) for a specified number of seconds until

a connection becomes available.

Use `max\_connections` to increase / decrease the pool size:

```

>>> pool = BlockingConnectionPool(max\_connections=10)

```

Use `timeout` to tell it either how many seconds to wait for a connection

to become available, or to block forever:

> 

> # Block forever.

> >>> pool = BlockingConnectionPool(timeout=None)

> 

> 

> # Raise a `ConnectionError` after five seconds if a connection is

> # not available.

> >>> pool = BlockingConnectionPool(timeout=5)

> 

> 

> 

disconnect()[[source]](_modules/redis/connection.html#BlockingConnectionPool.disconnect)[¶](#redis.BlockingConnectionPool.disconnect "Permalink to this definition")

Disconnects all connections in the pool.

get\_connection(*command\_name*, *\*keys*, *\*\*options*)[[source]](_modules/redis/connection.html#BlockingConnectionPool.get_connection)[¶](#redis.BlockingConnectionPool.get_connection "Permalink to this definition")

Get a connection, blocking for `self.timeout` until a connection

is available from the pool.

If the connection returned is `None` then creates a new connection.

Because we use a last-in first-out queue, the existing connections

(having been returned to the pool after the initial `None` values

were added) will be returned before `None` values. This means we only

create new connections when we need to, i.e.: the actual number of

connections will only increase in response to demand.

make\_connection()[[source]](_modules/redis/connection.html#BlockingConnectionPool.make_connection)[¶](#redis.BlockingConnectionPool.make_connection "Permalink to this definition")

Make a fresh connection.

release(*connection*)[[source]](_modules/redis/connection.html#BlockingConnectionPool.release)[¶](#redis.BlockingConnectionPool.release "Permalink to this definition")

Releases the connection back to the pool.

*exception* redis.BusyLoadingError[[source]](_modules/redis/exceptions.html#BusyLoadingError)[¶](#redis.BusyLoadingError "Permalink to this definition")

*exception* redis.ChildDeadlockedError[[source]](_modules/redis/exceptions.html#ChildDeadlockedError)[¶](#redis.ChildDeadlockedError "Permalink to this definition")

Error indicating that a child process is deadlocked after a fork()

*class* redis.Connection(*host='localhost'*, *port=6379*, *db=0*, *password=None*, *socket\_timeout=None*, *socket\_connect\_timeout=None*, *socket\_keepalive=False*, *socket\_keepalive\_options=None*, *socket\_type=0*, *retry\_on\_timeout=False*, *encoding='utf-8'*, *encoding\_errors='strict'*, *decode\_responses=False*, *parser\_class=<class 'redis.connection.PythonParser'>*, *socket\_read\_size=65536*, *health\_check\_interval=0*, *client\_name=None*, *username=None*)[[source]](_modules/redis/connection.html#Connection)[¶](#redis.Connection "Permalink to this definition")

Manages TCP communication to and from a Redis server

can\_read(*timeout=0*)[[source]](_modules/redis/connection.html#Connection.can_read)[¶](#redis.Connection.can_read "Permalink to this definition")

Poll the socket to see if there’s data that can be read.

check\_health()[[source]](_modules/redis/connection.html#Connection.check_health)[¶](#redis.Connection.check_health "Permalink to this definition")

Check the health of the connection with a PING/PONG

connect()[[source]](_modules/redis/connection.html#Connection.connect)[¶](#redis.Connection.connect "Permalink to this definition")

Connects to the Redis server if not already connected

disconnect()[[source]](_modules/redis/connection.html#Connection.disconnect)[¶](#redis.Connection.disconnect "Permalink to this definition")

Disconnects from the Redis server

on\_connect()[[source]](_modules/redis/connection.html#Connection.on_connect)[¶](#redis.Connection.on_connect "Permalink to this definition")

Initialize the connection, authenticate and select a database

pack\_command(*\*args*)[[source]](_modules/redis/connection.html#Connection.pack_command)[¶](#redis.Connection.pack_command "Permalink to this definition")

Pack a series of arguments into the Redis protocol

pack\_commands(*commands*)[[source]](_modules/redis/connection.html#Connection.pack_commands)[¶](#redis.Connection.pack_commands "Permalink to this definition")

Pack multiple commands into the Redis protocol

read\_response()[[source]](_modules/redis/connection.html#Connection.read_response)[¶](#redis.Connection.read_response "Permalink to this definition")

Read the response from a previously sent command

send\_command(*\*args*, *\*\*kwargs*)[[source]](_modules/redis/connection.html#Connection.send_command)[¶](#redis.Connection.send_command "Permalink to this definition")

Pack and send a command to the Redis server

send\_packed\_command(*command*, *check\_health=True*)[[source]](_modules/redis/connection.html#Connection.send_packed_command)[¶](#redis.Connection.send_packed_command "Permalink to this definition")

Send an already packed command to the Redis server

*exception* redis.ConnectionError[[source]](_modules/redis/exceptions.html#ConnectionError)[¶](#redis.ConnectionError "Permalink to this definition")

*class* redis.ConnectionPool(*connection\_class=<class 'redis.connection.Connection'>*, *max\_connections=None*, *\*\*connection\_kwargs*)[[source]](_modules/redis/connection.html#ConnectionPool)[¶](#redis.ConnectionPool "Permalink to this definition")

Generic connection pool

disconnect(*inuse\_connections=True*)[[source]](_modules/redis/connection.html#ConnectionPool.disconnect)[¶](#redis.ConnectionPool.disconnect "Permalink to this definition")

Disconnects connections in the pool

If `inuse\_connections` is True, disconnect connections that are

current in use, potentially by other threads. Otherwise only disconnect

connections that are idle in the pool.

*classmethod* from\_url(*url*, *db=None*, *decode\_components=False*, *\*\*kwargs*)[[source]](_modules/redis/connection.html#ConnectionPool.from_url)[¶](#redis.ConnectionPool.from_url "Permalink to this definition")

Return a connection pool configured from the given URL.

For example:

```

redis://[[username]:[password]]@localhost:6379/0

rediss://[[username]:[password]]@localhost:6379/0

unix://[[username]:[password]]@/path/to/socket.sock?db=0

```

Three URL schemes are supported:

* ``redis://`

<<https://www.iana.org/assignments/uri-schemes/prov/redis>>`\_ creates a

normal TCP socket connection

* ``rediss://`

<<https://www.iana.org/assignments/uri-schemes/prov/rediss>>`\_ creates

a SSL wrapped TCP socket connection

* `unix://` creates a Unix Domain Socket connection

There are several ways to specify a database number. The parse function

will return the first specified option:

> 

> 1. A `db` querystring option, e.g. redis://localhost?db=0

> 2. If using the redis:// scheme, the path argument of the url, e.g.

> redis://localhost/0

> 3. The `db` argument to this function.

> 

> 

> 

If none of these options are specified, db=0 is used.

The `decode\_components` argument allows this function to work with

percent-encoded URLs. If this argument is set to `True` all `%xx`

escapes will be replaced by their single-character equivalents after

the URL has been parsed. This only applies to the `hostname`,

`path`, `username` and `password` components.

Any additional querystring arguments and keyword arguments will be

passed along to the ConnectionPool class’s initializer. The querystring

arguments `socket\_connect\_timeout` and `socket\_timeout` if supplied

are parsed as float values. The arguments `socket\_keepalive` and

`retry\_on\_timeout` are parsed to boolean values that accept

True/False, Yes/No values to indicate state. Invalid types cause a

`UserWarning` to be raised. In the case of conflicting arguments,

querystring arguments always win.

get\_connection(*command\_name*, *\*keys*, *\*\*options*)[[source]](_modules/redis/connection.html#ConnectionPool.get_connection)[¶](#redis.ConnectionPool.get_connection "Permalink to this definition")

Get a connection from the pool

get\_encoder()[[source]](_modules/redis/connection.html#ConnectionPool.get_encoder)[¶](#redis.ConnectionPool.get_encoder "Permalink to this definition")

Return an encoder based on encoding settings

make\_connection()[[source]](_modules/redis/connection.html#ConnectionPool.make_connection)[¶](#redis.ConnectionPool.make_connection "Permalink to this definition")

Create a new connection

release(*connection*)[[source]](_modules/redis/connection.html#ConnectionPool.release)[¶](#redis.ConnectionPool.release "Permalink to this definition")

Releases the connection back to the pool

*exception* redis.DataError[[source]](_modules/redis/exceptions.html#DataError)[¶](#redis.DataError "Permalink to this definition")

*exception* redis.InvalidResponse[[source]](_modules/redis/exceptions.html#InvalidResponse)[¶](#redis.InvalidResponse "Permalink to this definition")

*exception* redis.PubSubError[[source]](_modules/redis/exceptions.html#PubSubError)[¶](#redis.PubSubError "Permalink to this definition")

*exception* redis.ReadOnlyError[[source]](_modules/redis/exceptions.html#ReadOnlyError)[¶](#redis.ReadOnlyError "Permalink to this definition")

*class* redis.Redis(*host='localhost'*, *port=6379*, *db=0*, *password=None*, *socket\_timeout=None*, *socket\_connect\_timeout=None*, *socket\_keepalive=None*, *socket\_keepalive\_options=None*, *connection\_pool=None*, *unix\_socket\_path=None*, *encoding='utf-8'*, *encoding\_errors='strict'*, *charset=None*, *errors=None*, *decode\_responses=False*, *retry\_on\_timeout=False*, *ssl=False*, *ssl\_keyfile=None*, *ssl\_certfile=None*, *ssl\_cert\_reqs='required'*, *ssl\_ca\_certs=None*, *ssl\_check\_hostname=False*, *max\_connections=None*, *single\_connection\_client=False*, *health\_check\_interval=0*, *client\_name=None*, *username=None*)[[source]](_modules/redis/client.html#Redis)[¶](#redis.Redis "Permalink to this definition")

Implementation of the Redis protocol.

This abstract class provides a Python interface to all Redis commands

and an implementation of the Redis protocol.

Connection and Pipeline derive from this, implementing how

the commands are sent and received to the Redis server

acl\_cat(*category=None*)[[source]](_modules/redis/client.html#Redis.acl_cat)[¶](#redis.Redis.acl_cat "Permalink to this definition")

Returns a list of categories or commands within a category.

If `category` is not supplied, returns a list of all categories.

If `category` is supplied, returns a list of all commands within

that category.

acl\_deluser(*username*)[[source]](_modules/redis/client.html#Redis.acl_deluser)[¶](#redis.Redis.acl_deluser "Permalink to this definition")

Delete the ACL for the specified `username`

acl\_genpass()[[source]](_modules/redis/client.html#Redis.acl_genpass)[¶](#redis.Redis.acl_genpass "Permalink to this definition")

Generate a random password value

acl\_getuser(*username*)[[source]](_modules/redis/client.html#Redis.acl_getuser)[¶](#redis.Redis.acl_getuser "Permalink to this definition")

Get the ACL details for the specified `username`.

If `username` does not exist, return None

acl\_list()[[source]](_modules/redis/client.html#Redis.acl_list)[¶](#redis.Redis.acl_list "Permalink to this definition")

Return a list of all ACLs on the server

acl\_load()[[source]](_modules/redis/client.html#Redis.acl_load)[¶](#redis.Redis.acl_load "Permalink to this definition")

Load ACL rules from the configured `aclfile`.

Note that the server must be configured with the `aclfile`

directive to be able to load ACL rules from an aclfile.

acl\_save()[[source]](_modules/redis/client.html#Redis.acl_save)[¶](#redis.Redis.acl_save "Permalink to this definition")

Save ACL rules to the configured `aclfile`.

Note that the server must be configured with the `aclfile`

directive to be able to save ACL rules to an aclfile.

acl\_setuser(*username*, *enabled=False*, *nopass=False*, *passwords=None*, *hashed\_passwords=None*, *categories=None*, *commands=None*, *keys=None*, *reset=False*, *reset\_keys=False*, *reset\_passwords=False*)[[source]](_modules/redis/client.html#Redis.acl_setuser)[¶](#redis.Redis.acl_setuser "Permalink to this definition")

Create or update an ACL user.

Create or update the ACL for `username`. If the user already exists,

the existing ACL is completely overwritten and replaced with the

specified values.

`enabled` is a boolean indicating whether the user should be allowed

to authenticate or not. Defaults to `False`.

`nopass` is a boolean indicating whether the can authenticate without

a password. This cannot be True if `passwords` are also specified.

`passwords` if specified is a list of plain text passwords

to add to or remove from the user. Each password must be prefixed with

a ‘+’ to add or a ‘-’ to remove. For convenience, the value of

`add\_passwords` can be a simple prefixed string when adding or

removing a single password.

`hashed\_passwords` if specified is a list of SHA-256 hashed passwords

to add to or remove from the user. Each hashed password must be

prefixed with a ‘+’ to add or a ‘-’ to remove. For convenience,

the value of `hashed\_passwords` can be a simple prefixed string when

adding or removing a single password.

`categories` if specified is a list of strings representing category

permissions. Each string must be prefixed with either a ‘+’ to add the

category permission or a ‘-’ to remove the category permission.

`commands` if specified is a list of strings representing command

permissions. Each string must be prefixed with either a ‘+’ to add the

command permission or a ‘-’ to remove the command permission.

`keys` if specified is a list of key patterns to grant the user

access to. Keys patterns allow ‘\*’ to support wildcard matching. For

example, ‘\*’ grants access to all keys while ‘cache:[\*](#id1)’ grants access

to all keys that are prefixed with ‘cache:’. `keys` should not be

prefixed with a ‘~’.

`reset` is a boolean indicating whether the user should be fully

reset prior to applying the new ACL. Setting this to True will

remove all existing passwords, flags and privileges from the user and

then apply the specified rules. If this is False, the user’s existing

passwords, flags and privileges will be kept and any new specified

rules will be applied on top.

`reset\_keys` is a boolean indicating whether the user’s key

permissions should be reset prior to applying any new key permissions

specified in `keys`. If this is False, the user’s existing

key permissions will be kept and any new specified key permissions

will be applied on top.

`reset\_passwords` is a boolean indicating whether to remove all

existing passwords and the ‘nopass’ flag from the user prior to

applying any new passwords specified in ‘passwords’ or

‘hashed\_passwords’. If this is False, the user’s existing passwords

and ‘nopass’ status will be kept and any new specified passwords

or hashed\_passwords will be applied on top.

acl\_users()[[source]](_modules/redis/client.html#Redis.acl_users)[¶](#redis.Redis.acl_users "Permalink to this definition")

Returns a list of all registered users on the server.

acl\_whoami()[[source]](_modules/redis/client.html#Redis.acl_whoami)[¶](#redis.Redis.acl_whoami "Permalink to this definition")

Get the username for the current connection

append(*key*, *value*)[[source]](_modules/redis/client.html#Redis.append)[¶](#redis.Redis.append "Permalink to this definition")

Appends the string `value` to the value at `key`. If `key`

doesn’t already exist, create it with a value of `value`.

Returns the new length of the value at `key`.

bgrewriteaof()[[source]](_modules/redis/client.html#Redis.bgrewriteaof)[¶](#redis.Redis.bgrewriteaof "Permalink to this definition")

Tell the Redis server to rewrite the AOF file from data in memory.

bgsave()[[source]](_modules/redis/client.html#Redis.bgsave)[¶](#redis.Redis.bgsave "Permalink to this definition")

Tell the Redis server to save its data to disk. Unlike save(),

this method is asynchronous and returns immediately.

bitcount(*key*, *start=None*, *end=None*)[[source]](_modules/redis/client.html#Redis.bitcount)[¶](#redis.Redis.bitcount "Permalink to this definition")

Returns the count of set bits in the value of `key`. Optional

`start` and `end` paramaters indicate which bytes to consider

bitfield(*key*, *default\_overflow=None*)[[source]](_modules/redis/client.html#Redis.bitfield)[¶](#redis.Redis.bitfield "Permalink to this definition")

Return a BitFieldOperation instance to conveniently construct one or

more bitfield operations on `key`.

bitop(*operation*, *dest*, *\*keys*)[[source]](_modules/redis/client.html#Redis.bitop)[¶](#redis.Redis.bitop "Permalink to this definition")

Perform a bitwise operation using `operation` between `keys` and

store the result in `dest`.

bitpos(*key*, *bit*, *start=None*, *end=None*)[[source]](_modules/redis/client.html#Redis.bitpos)[¶](#redis.Redis.bitpos "Permalink to this definition")

Return the position of the first bit set to 1 or 0 in a string.

`start` and `end` difines search range. The range is interpreted

as a range of bytes and not a range of bits, so start=0 and end=2

means to look at the first three bytes.

blpop(*keys*, *timeout=0*)[[source]](_modules/redis/client.html#Redis.blpop)[¶](#redis.Redis.blpop "Permalink to this definition")

LPOP a value off of the first non-empty list

named in the `keys` list.

If none of the lists in `keys` has a value to LPOP, then block

for `timeout` seconds, or until a value gets pushed on to one

of the lists.

If timeout is 0, then block indefinitely.

brpop(*keys*, *timeout=0*)[[source]](_modules/redis/client.html#Redis.brpop)[¶](#redis.Redis.brpop "Permalink to this definition")

RPOP a value off of the first non-empty list

named in the `keys` list.

If none of the lists in `keys` has a value to RPOP, then block

for `timeout` seconds, or until a value gets pushed on to one

of the lists.

If timeout is 0, then block indefinitely.

brpoplpush(*src*, *dst*, *timeout=0*)[[source]](_modules/redis/client.html#Redis.brpoplpush)[¶](#redis.Redis.brpoplpush "Permalink to this definition")

Pop a value off the tail of `src`, push it on the head of `dst`

and then return it.

This command blocks until a value is in `src` or until `timeout`

seconds elapse, whichever is first. A `timeout` value of 0 blocks

forever.

bzpopmax(*keys*, *timeout=0*)[[source]](_modules/redis/client.html#Redis.bzpopmax)[¶](#redis.Redis.bzpopmax "Permalink to this definition")

ZPOPMAX a value off of the first non-empty sorted set

named in the `keys` list.

If none of the sorted sets in `keys` has a value to ZPOPMAX,

then block for `timeout` seconds, or until a member gets added

to one of the sorted sets.

If timeout is 0, then block indefinitely.

bzpopmin(*keys*, *timeout=0*)[[source]](_modules/redis/client.html#Redis.bzpopmin)[¶](#redis.Redis.bzpopmin "Permalink to this definition")

ZPOPMIN a value off of the first non-empty sorted set

named in the `keys` list.

If none of the sorted sets in `keys` has a value to ZPOPMIN,

then block for `timeout` seconds, or until a member gets added

to one of the sorted sets.

If timeout is 0, then block indefinitely.

client\_getname()[[source]](_modules/redis/client.html#Redis.client_getname)[¶](#redis.Redis.client_getname "Permalink to this definition")

Returns the current connection name

client\_id()[[source]](_modules/redis/client.html#Redis.client_id)[¶](#redis.Redis.client_id "Permalink to this definition")

Returns the current connection id

client\_kill(*address*)[[source]](_modules/redis/client.html#Redis.client_kill)[¶](#redis.Redis.client_kill "Permalink to this definition")

Disconnects the client at `address` (ip:port)

client\_kill\_filter(*\_id=None*, *\_type=None*, *addr=None*, *skipme=None*)[[source]](_modules/redis/client.html#Redis.client_kill_filter)[¶](#redis.Redis.client_kill_filter "Permalink to this definition")

Disconnects client(s) using a variety of filter options

:param id: Kills a client by its unique ID field

:param type: Kills a client by type where type is one of ‘normal’,

‘master’, ‘slave’ or ‘pubsub’

:param addr: Kills a client by its ‘address:port’

:param skipme: If True, then the client calling the command

will not get killed even if it is identified by one of the filter

options. If skipme is not provided, the server defaults to skipme=True

client\_list(*\_type=None*)[[source]](_modules/redis/client.html#Redis.client_list)[¶](#redis.Redis.client_list "Permalink to this definition")

Returns a list of currently connected clients.

If type of client specified, only that type will be returned.

:param \_type: optional. one of the client types (normal, master,

> 

> replica, pubsub)

> 

> 

> 

client\_pause(*timeout*)[[source]](_modules/redis/client.html#Redis.client_pause)[¶](#redis.Redis.client_pause "Permalink to this definition")

Suspend all the Redis clients for the specified amount of time

:param timeout: milliseconds to pause clients

client\_setname(*name*)[[source]](_modules/redis/client.html#Redis.client_setname)[¶](#redis.Redis.client_setname "Permalink to this definition")

Sets the current connection name

client\_unblock(*client\_id*, *error=False*)[[source]](_modules/redis/client.html#Redis.client_unblock)[¶](#redis.Redis.client_unblock "Permalink to this definition")

Unblocks a connection by its client id.

If `error` is True, unblocks the client with a special error message.

If `error` is False (default), the client is unblocked using the

regular timeout mechanism.

config\_get(*pattern='\*'*)[[source]](_modules/redis/client.html#Redis.config_get)[¶](#redis.Redis.config_get "Permalink to this definition")

Return a dictionary of configuration based on the `pattern`

config\_resetstat()[[source]](_modules/redis/client.html#Redis.config_resetstat)[¶](#redis.Redis.config_resetstat "Permalink to this definition")

Reset runtime statistics

config\_rewrite()[[source]](_modules/redis/client.html#Redis.config_rewrite)[¶](#redis.Redis.config_rewrite "Permalink to this definition")

Rewrite config file with the minimal change to reflect running config

config\_set(*name*, *value*)[[source]](_modules/redis/client.html#Redis.config_set)[¶](#redis.Redis.config_set "Permalink to this definition")

Set config item `name` with `value`

dbsize()[[source]](_modules/redis/client.html#Redis.dbsize)[¶](#redis.Redis.dbsize "Permalink to this definition")

Returns the number of keys in the current database

debug\_object(*key*)[[source]](_modules/redis/client.html#Redis.debug_object)[¶](#redis.Redis.debug_object "Permalink to this definition")

Returns version specific meta information about a given key

decr(*name*, *amount=1*)[[source]](_modules/redis/client.html#Redis.decr)[¶](#redis.Redis.decr "Permalink to this definition")

Decrements the value of `key` by `amount`. If no key exists,

the value will be initialized as 0 - `amount`

decrby(*name*, *amount=1*)[[source]](_modules/redis/client.html#Redis.decrby)[¶](#redis.Redis.decrby "Permalink to this definition")

Decrements the value of `key` by `amount`. If no key exists,

the value will be initialized as 0 - `amount`

delete(*\*names*)[[source]](_modules/redis/client.html#Redis.delete)[¶](#redis.Redis.delete "Permalink to this definition")

Delete one or more keys specified by `names`

dump(*name*)[[source]](_modules/redis/client.html#Redis.dump)[¶](#redis.Redis.dump "Permalink to this definition")

Return a serialized version of the value stored at the specified key.

If key does not exist a nil bulk reply is returned.

echo(*value*)[[source]](_modules/redis/client.html#Redis.echo)[¶](#redis.Redis.echo "Permalink to this definition")

Echo the string back from the server

eval(*script*, *numkeys*, *\*keys\_and\_args*)[[source]](_modules/redis/client.html#Redis.eval)[¶](#redis.Redis.eval "Permalink to this definition")

Execute the Lua `script`, specifying the `numkeys` the script

will touch and the key names and argument values in `keys\_and\_args`.

Returns the result of the script.

In practice, use the object returned by `register\_script`. This

function exists purely for Redis API completion.

evalsha(*sha*, *numkeys*, *\*keys\_and\_args*)[[source]](_modules/redis/client.html#Redis.evalsha)[¶](#redis.Redis.evalsha "Permalink to this definition")

Use the `sha` to execute a Lua script already registered via EVAL

or SCRIPT LOAD. Specify the `numkeys` the script will touch and the

key names and argument values in `keys\_and\_args`. Returns the result

of the script.

In practice, use the object returned by `register\_script`. This

function exists purely for Redis API completion.

execute\_command(*\*args*, *\*\*options*)[[source]](_modules/redis/client.html#Redis.execute_command)[¶](#redis.Redis.execute_command "Permalink to this definition")

Execute a command and return a parsed response

exists(*\*names*)[[source]](_modules/redis/client.html#Redis.exists)[¶](#redis.Redis.exists "Permalink to this definition")

Returns the number of `names` that exist

expire(*name*, *time*)[[source]](_modules/redis/client.html#Redis.expire)[¶](#redis.Redis.expire "Permalink to this definition")

Set an expire flag on key `name` for `time` seconds. `time`

can be represented by an integer or a Python timedelta object.

expireat(*name*, *when*)[[source]](_modules/redis/client.html#Redis.expireat)[¶](#redis.Redis.expireat "Permalink to this definition")

Set an expire flag on key `name`. `when` can be represented

as an integer indicating unix time or a Python datetime object.

flushall(*asynchronous=False*)[[source]](_modules/redis/client.html#Redis.flushall)[¶](#redis.Redis.flushall "Permalink to this definition")

Delete all keys in all databases on the current host.

`asynchronous` indicates whether the operation is

executed asynchronously by the server.

flushdb(*asynchronous=False*)[[source]](_modules/redis/client.html#Redis.flushdb)[¶](#redis.Redis.flushdb "Permalink to this definition")

Delete all keys in the current database.

`asynchronous` indicates whether the operation is

executed asynchronously by the server.

*classmethod* from\_url(*url*, *db=None*, *\*\*kwargs*)[[source]](_modules/redis/client.html#Redis.from_url)[¶](#redis.Redis.from_url "Permalink to this definition")

Return a Redis client object configured from the given URL

For example:

```

redis://[[username]:[password]]@localhost:6379/0

rediss://[[username]:[password]]@localhost:6379/0

unix://[[username]:[password]]@/path/to/socket.sock?db=0

```

Three URL schemes are supported:

* ``redis://`

<<http://www.iana.org/assignments/uri-schemes/prov/redis>>`\_ creates a

normal TCP socket connection

* ``rediss://`

<<http://www.iana.org/assignments/uri-schemes/prov/rediss>>`\_ creates a

SSL wrapped TCP socket connection

* `unix://` creates a Unix Domain Socket connection

There are several ways to specify a database number. The parse function

will return the first specified option:

> 

> 1. A `db` querystring option, e.g. redis://localhost?db=0

> 2. If using the redis:// scheme, the path argument of the url, e.g.

> redis://localhost/0

> 3. The `db` argument to this function.

> 

> 

> 

If none of these options are specified, db=0 is used.

Any additional querystring arguments and keyword arguments will be

passed along to the ConnectionPool class’s initializer. In the case

of conflicting arguments, querystring arguments always win.

geoadd(*name*, *\*values*)[[source]](_modules/redis/client.html#Redis.geoadd)[¶](#redis.Redis.geoadd "Permalink to this definition")

Add the specified geospatial items to the specified key identified

by the `name` argument. The Geospatial items are given as ordered

members of the `values` argument, each item or place is formed by

the triad longitude, latitude and name.

geodist(*name*, *place1*, *place2*, *unit=None*)[[source]](_modules/redis/client.html#Redis.geodist)[¶](#redis.Redis.geodist "Permalink to this definition")

Return the distance between `place1` and `place2` members of the

`name` key.

The units must be one of the following : m, km mi, ft. By default

meters are used.

geohash(*name*, *\*values*)[[source]](_modules/redis/client.html#Redis.geohash)[¶](#redis.Redis.geohash "Permalink to this definition")

Return the geo hash string for each item of `values` members of

the specified key identified by the `name` argument.

geopos(*name*, *\*values*)[[source]](_modules/redis/client.html#Redis.geopos)[¶](#redis.Redis.geopos "Permalink to this definition")

Return the positions of each item of `values` as members of

the specified key identified by the `name` argument. Each position

is represented by the pairs lon and lat.

georadius(*name*, *longitude*, *latitude*, *radius*, *unit=None*, *withdist=False*, *withcoord=False*, *withhash=False*, *count=None*, *sort=None*, *store=None*, *store\_dist=None*)[[source]](_modules/redis/client.html#Redis.georadius)[¶](#redis.Redis.georadius "Permalink to this definition")

Return the members of the specified key identified by the

`name` argument which are within the borders of the area specified

with the `latitude` and `longitude` location and the maximum

distance from the center specified by the `radius` value.

The units must be one of the following : m, km mi, ft. By default

`withdist` indicates to return the distances of each place.

`withcoord` indicates to return the latitude and longitude of

each place.

`withhash` indicates to return the geohash string of each place.

`count` indicates to return the number of elements up to N.

`sort` indicates to return the places in a sorted way, ASC for

nearest to fairest and DESC for fairest to nearest.

`store` indicates to save the places names in a sorted set named

with a specific key, each element of the destination sorted set is

populated with the score got from the original geo sorted set.

`store\_dist` indicates to save the places names in a sorted set

named with a specific key, instead of `store` the sorted set

destination score is set with the distance.

georadiusbymember(*name*, *member*, *radius*, *unit=None*, *withdist=False*, *withcoord=False*, *withhash=False*, *count=None*, *sort=None*, *store=None*, *store\_dist=None*)[[source]](_modules/redis/client.html#Redis.georadiusbymember)[¶](#redis.Redis.georadiusbymember "Permalink to this definition")

This command is exactly like `georadius` with the sole difference

that instead of taking, as the center of the area to query, a longitude

and latitude value, it takes the name of a member already existing

inside the geospatial index represented by the sorted set.

get(*name*)[[source]](_modules/redis/client.html#Redis.get)[¶](#redis.Redis.get "Permalink to this definition")

Return the value at key `name`, or None if the key doesn’t exist

getbit(*name*, *offset*)[[source]](_modules/redis/client.html#Redis.getbit)[¶](#redis.Redis.getbit "Permalink to this definition")

Returns a boolean indicating the value of `offset` in `name`

getrange(*key*, *start*, *end*)[[source]](_modules/redis/client.html#Redis.getrange)[¶](#redis.Redis.getrange "Permalink to this definition")

Returns the substring of the string value stored at `key`,

determined by the offsets `start` and `end` (both are inclusive)

getset(*name*, *value*)[[source]](_modules/redis/client.html#Redis.getset)[¶](#redis.Redis.getset "Permalink to this definition")

Sets the value at key `name` to `value`

and returns the old value at key `name` atomically.

hdel(*name*, *\*keys*)[[source]](_modules/redis/client.html#Redis.hdel)[¶](#redis.Redis.hdel "Permalink to this definition")

Delete `keys` from hash `name`

hexists(*name*, *key*)[[source]](_modules/redis/client.html#Redis.hexists)[¶](#redis.Redis.hexists "Permalink to this definition")

Returns a boolean indicating if `key` exists within hash `name`

hget(*name*, *key*)[[source]](_modules/redis/client.html#Redis.hget)[¶](#redis.Redis.hget "Permalink to this definition")

Return the value of `key` within the hash `name`

hgetall(*name*)[[source]](_modules/redis/client.html#Redis.hgetall)[¶](#redis.Redis.hgetall "Permalink to this definition")

Return a Python dict of the hash’s name/value pairs

hincrby(*name*, *key*, *amount=1*)[[source]](_modules/redis/client.html#Redis.hincrby)[¶](#redis.Redis.hincrby "Permalink to this definition")

Increment the value of `key` in hash `name` by `amount`

hincrbyfloat(*name*, *key*, *amount=1.0*)[[source]](_modules/redis/client.html#Redis.hincrbyfloat)[¶](#redis.Redis.hincrbyfloat "Permalink to this definition")

Increment the value of `key` in hash `name` by floating `amount`

hkeys(*name*)[[source]](_modules/redis/client.html#Redis.hkeys)[¶](#redis.Redis.hkeys "Permalink to this definition")

Return the list of keys within hash `name`

hlen(*name*)[[source]](_modules/redis/client.html#Redis.hlen)[¶](#redis.Redis.hlen "Permalink to this definition")

Return the number of elements in hash `name`

hmget(*name*, *keys*, *\*args*)[[source]](_modules/redis/client.html#Redis.hmget)[¶](#redis.Redis.hmget "Permalink to this definition")

Returns a list of values ordered identically to `keys`

hmset(*name*, *mapping*)[[source]](_modules/redis/client.html#Redis.hmset)[¶](#redis.Redis.hmset "Permalink to this definition")

Set key to value within hash `name` for each corresponding

key and value from the `mapping` dict.

hscan(*name*, *cursor=0*, *match=None*, *count=None*)[[source]](_modules/redis/client.html#Redis.hscan)[¶](#redis.Redis.hscan "Permalink to this definition")

Incrementally return key/value slices in a hash. Also return a cursor

indicating the scan position.

`match` allows for filtering the keys by pattern

`count` allows for hint the minimum number of returns

hscan\_iter(*name*, *match=None*, *count=None*)[[source]](_modules/redis/client.html#Redis.hscan_iter)[¶](#redis.Redis.hscan_iter "Permalink to this definition")

Make an iterator using the HSCAN command so that the client doesn’t

need to remember the cursor position.

`match` allows for filtering the keys by pattern

`count` allows for hint the minimum number of returns

hset(*name*, *key=None*, *value=None*, *mapping=None*)[[source]](_modules/redis/client.html#Redis.hset)[¶](#redis.Redis.hset "Permalink to this definition")

Set `key` to `value` within hash `name`,

`mapping` accepts a dict of key/value pairs that that will be

added to hash `name`.

Returns the number of fields that were added.

hsetnx(*name*, *key*, *value*)[[source]](_modules/redis/client.html#Redis.hsetnx)[¶](#redis.Redis.hsetnx "Permalink to this definition")

Set `key` to `value` within hash `name` if `key` does not

exist. Returns 1 if HSETNX created a field, otherwise 0.

hstrlen(*name*, *key*)[[source]](_modules/redis/client.html#Redis.hstrlen)[¶](#redis.Redis.hstrlen "Permalink to this definition")

Return the number of bytes stored in the value of `key`

within hash `name`

hvals(*name*)[[source]](_modules/redis/client.html#Redis.hvals)[¶](#redis.Redis.hvals "Permalink to this definition")

Return the list of values within hash `name`

incr(*name*, *amount=1*)[[source]](_modules/redis/client.html#Redis.incr)[¶](#redis.Redis.incr "Permalink to this definition")

Increments the value of `key` by `amount`. If no key exists,

the value will be initialized as `amount`

incrby(*name*, *amount=1*)[[source]](_modules/redis/client.html#Redis.incrby)[¶](#redis.Redis.incrby "Permalink to this definition")

Increments the value of `key` by `amount`. If no key exists,

the value will be initialized as `amount`

incrbyfloat(*name*, *amount=1.0*)[[source]](_modules/redis/client.html#Redis.incrbyfloat)[¶](#redis.Redis.incrbyfloat "Permalink to this definition")

Increments the value at key `name` by floating `amount`.

If no key exists, the value will be initialized as `amount`

info(*section=None*)[[source]](_modules/redis/client.html#Redis.info)[¶](#redis.Redis.info "Permalink to this definition")

Returns a dictionary containing information about the Redis server

The `section` option can be used to select a specific section

of information

The section option is not supported by older versions of Redis Server,

and will generate ResponseError

keys(*pattern='\*'*)[[source]](_modules/redis/client.html#Redis.keys)[¶](#redis.Redis.keys "Permalink to this definition")

Returns a list of keys matching `pattern`

lastsave()[[source]](_modules/redis/client.html#Redis.lastsave)[¶](#redis.Redis.lastsave "Permalink to this definition")

Return a Python datetime object representing the last time the

Redis database was saved to disk

lindex(*name*, *index*)[[source]](_modules/redis/client.html#Redis.lindex)[¶](#redis.Redis.lindex "Permalink to this definition")

Return the item from list `name` at position `index`

Negative indexes are supported and will return an item at the

end of the list

linsert(*name*, *where*, *refvalue*, *value*)[[source]](_modules/redis/client.html#Redis.linsert)[¶](#redis.Redis.linsert "Permalink to this definition")

Insert `value` in list `name` either immediately before or after

[`where`] `refvalue`

Returns the new length of the list on success or -1 if `refvalue`

is not in the list.

llen(*name*)[[source]](_modules/redis/client.html#Redis.llen)[¶](#redis.Redis.llen "Permalink to this definition")

Return the length of the list `name`

lock(*name*, *timeout=None*, *sleep=0.1*, *blocking\_timeout=None*, *lock\_class=None*, *thread\_local=True*)[[source]](_modules/redis/client.html#Redis.lock)[¶](#redis.Redis.lock "Permalink to this definition")

Return a new Lock object using key `name` that mimics

the behavior of threading.Lock.

If specified, `timeout` indicates a maximum life for the lock.

By default, it will remain locked until release() is called.

`sleep` indicates the amount of time to sleep per loop iteration

when the lock is in blocking mode and another client is currently

holding the lock.

`blocking\_timeout` indicates the maximum amount of time in seconds to

spend trying to acquire the lock. A value of `None` indicates

continue trying forever. `blocking\_timeout` can be specified as a

float or integer, both representing the number of seconds to wait.

`lock\_class` forces the specified lock implementation.

`thread\_local` indicates whether the lock token is placed in

thread-local storage. By default, the token is placed in thread local

storage so that a thread only sees its token, not a token set by

another thread. Consider the following timeline:

> 

> 

> time: 0, thread-1 acquires my-lock, with a timeout of 5 seconds.thread-1 sets the token to “abc”

> 

> 

> 

> time: 1, thread-2 blocks trying to acquire my-lock using theLock instance.

> 

> 

> 

> time: 5, thread-1 has not yet completed. redis expires the lockkey.

> 

> 

> 

> time: 5, thread-2 acquired my-lock now that it’s available.thread-2 sets the token to “xyz”

> 

> 

> 

> time: 6, thread-1 finishes its work and calls release(). if thetoken is *not* stored in thread local storage, then

> thread-1 would see the token value as “xyz” and would be

> able to successfully release the thread-2’s lock.

> 

> 

> 

> 

> 

In some use cases it’s necessary to disable thread local storage. For

example, if you have code where one thread acquires a lock and passes

that lock instance to a worker thread to release later. If thread

local storage isn’t disabled in this case, the worker thread won’t see

the token set by the thread that acquired the lock. Our assumption

is that these cases aren’t common and as such default to using

thread local storage.

lpop(*name*)[[source]](_modules/redis/client.html#Redis.lpop)[¶](#redis.Redis.lpop "Permalink to this definition")

Remove and return the first item of the list `name`

lpush(*name*, *\*values*)[[source]](_modules/redis/client.html#Redis.lpush)[¶](#redis.Redis.lpush "Permalink to this definition")

Push `values` onto the head of the list `name`

lpushx(*name*, *value*)[[source]](_modules/redis/client.html#Redis.lpushx)[¶](#redis.Redis.lpushx "Permalink to this definition")

Push `value` onto the head of the list `name` if `name` exists

lrange(*name*, *start*, *end*)[[source]](_modules/redis/client.html#Redis.lrange)[¶](#redis.Redis.lrange "Permalink to this definition")

Return a slice of the list `name` between

position `start` and `end`

`start` and `end` can be negative numbers just like

Python slicing notation

lrem(*name*, *count*, *value*)[[source]](_modules/redis/client.html#Redis.lrem)[¶](#redis.Redis.lrem "Permalink to this definition")

Remove the first `count` occurrences of elements equal to `value`

from the list stored at `name`.

The count argument influences the operation in the following ways:count > 0: Remove elements equal to value moving from head to tail.

count < 0: Remove elements equal to value moving from tail to head.

count = 0: Remove all elements equal to value.

lset(*name*, *index*, *value*)[[source]](_modules/redis/client.html#Redis.lset)[¶](#redis.Redis.lset "Permalink to this definition")

Set `position` of list `name` to `value`

ltrim(*name*, *start*, *end*)[[source]](_modules/redis/client.html#Redis.ltrim)[¶](#redis.Redis.ltrim "Permalink to this definition")

Trim the list `name`, removing all values not within the slice

between `start` and `end`

`start` and `end` can be negative numbers just like

Python slicing notation

memory\_purge()[[source]](_modules/redis/client.html#Redis.memory_purge)[¶](#redis.Redis.memory_purge "Permalink to this definition")

Attempts to purge dirty pages for reclamation by allocator

memory\_stats()[[source]](_modules/redis/client.html#Redis.memory_stats)[¶](#redis.Redis.memory_stats "Permalink to this definition")

Return a dictionary of memory stats

memory\_usage(*key*, *samples=None*)[[source]](_modules/redis/client.html#Redis.memory_usage)[¶](#redis.Redis.memory_usage "Permalink to this definition")

Return the total memory usage for key, its value and associated

administrative overheads.

For nested data structures, `samples` is the number of elements to

sample. If left unspecified, the server’s default is 5. Use 0 to sample

all elements.

mget(*keys*, *\*args*)[[source]](_modules/redis/client.html#Redis.mget)[¶](#redis.Redis.mget "Permalink to this definition")

Returns a list of values ordered identically to `keys`

migrate(*host*, *port*, *keys*, *destination\_db*, *timeout*, *copy=False*, *replace=False*, *auth=None*)[[source]](_modules/redis/client.html#Redis.migrate)[¶](#redis.Redis.migrate "Permalink to this definition")

Migrate 1 or more keys from the current Redis server to a different

server specified by the `host`, `port` and `destination\_db`.

The `timeout`, specified in milliseconds, indicates the maximum

time the connection between the two servers can be idle before the

command is interrupted.

If `copy` is True, the specified `keys` are NOT deleted from

the source server.

If `replace` is True, this operation will overwrite the keys

on the destination server if they exist.

If `auth` is specified, authenticate to the destination server with

the password provided.

move(*name*, *db*)[[source]](_modules/redis/client.html#Redis.move)[¶](#redis.Redis.move "Permalink to this definition")

Moves the key `name` to a different Redis database `db`

mset(*mapping*)[[source]](_modules/redis/client.html#Redis.mset)[¶](#redis.Redis.mset "Permalink to this definition")

Sets key/values based on a mapping. Mapping is a dictionary of

key/value pairs. Both keys and values should be strings or types that

can be cast to a string via str().

msetnx(*mapping*)[[source]](_modules/redis/client.html#Redis.msetnx)[¶](#redis.Redis.msetnx "Permalink to this definition")

Sets key/values based on a mapping if none of the keys are already set.

Mapping is a dictionary of key/value pairs. Both keys and values

should be strings or types that can be cast to a string via str().

Returns a boolean indicating if the operation was successful.

object(*infotype*, *key*)[[source]](_modules/redis/client.html#Redis.object)[¶](#redis.Redis.object "Permalink to this definition")

Return the encoding, idletime, or refcount about the key

parse\_response(*connection*, *command\_name*, *\*\*options*)[[source]](_modules/redis/client.html#Redis.parse_response)[¶](#redis.Redis.parse_response "Permalink to this definition")

Parses a response from the Redis server

persist(*name*)[[source]](_modules/redis/client.html#Redis.persist)[¶](#redis.Redis.persist "Permalink to this definition")

Removes an expiration on `name`

pexpire(*name*, *time*)[[source]](_modules/redis/client.html#Redis.pexpire)[¶](#redis.Redis.pexpire "Permalink to this definition")

Set an expire flag on key `name` for `time` milliseconds.

`time` can be represented by an integer or a Python timedelta

object.

pexpireat(*name*, *when*)[[source]](_modules/redis/client.html#Redis.pexpireat)[¶](#redis.Redis.pexpireat "Permalink to this definition")

Set an expire flag on key `name`. `when` can be represented

as an integer representing unix time in milliseconds (unix time \* 1000)

or a Python datetime object.

pfadd(*name*, *\*values*)[[source]](_modules/redis/client.html#Redis.pfadd)[¶](#redis.Redis.pfadd "Permalink to this definition")

Adds the specified elements to the specified HyperLogLog.

pfcount(*\*sources*)[[source]](_modules/redis/client.html#Redis.pfcount)[¶](#redis.Redis.pfcount "Permalink to this definition")

Return the approximated cardinality of

the set observed by the HyperLogLog at key(s).

pfmerge(*dest*, *\*sources*)[[source]](_modules/redis/client.html#Redis.pfmerge)[¶](#redis.Redis.pfmerge "Permalink to this definition")

Merge N different HyperLogLogs into a single one.

ping()[[source]](_modules/redis/client.html#Redis.ping)[¶](#redis.Redis.ping "Permalink to this definition")

Ping the Redis server

pipeline(*transaction=True*, *shard\_hint=None*)[[source]](_modules/redis/client.html#Redis.pipeline)[¶](#redis.Redis.pipeline "Permalink to this definition")

Return a new pipeline object that can queue multiple commands for

later execution. `transaction` indicates whether all commands

should be executed atomically. Apart from making a group of operations

atomic, pipelines are useful for reducing the back-and-forth overhead

between the client and server.

psetex(*name*, *time\_ms*, *value*)[[source]](_modules/redis/client.html#Redis.psetex)[¶](#redis.Redis.psetex "Permalink to this definition")

Set the value of key `name` to `value` that expires in `time\_ms`

milliseconds. `time\_ms` can be represented by an integer or a Python

timedelta object

pttl(*name*)[[source]](_modules/redis/client.html#Redis.pttl)[¶](#redis.Redis.pttl "Permalink to this definition")

Returns the number of milliseconds until the key `name` will expire

publish(*channel*, *message*)[[source]](_modules/redis/client.html#Redis.publish)[¶](#redis.Redis.publish "Permalink to this definition")

Publish `message` on `channel`.

Returns the number of subscribers the message was delivered to.

pubsub(*\*\*kwargs*)[[source]](_modules/redis/client.html#Redis.pubsub)[¶](#redis.Redis.pubsub "Permalink to this definition")

Return a Publish/Subscribe object. With this object, you can

subscribe to channels and listen for messages that get published to

them.

pubsub\_channels(*pattern='\*'*)[[source]](_modules/redis/client.html#Redis.pubsub_channels)[¶](#redis.Redis.pubsub_channels "Permalink to this definition")

Return a list of channels that have at least one subscriber

pubsub\_numpat()[[source]](_modules/redis/client.html#Redis.pubsub_numpat)[¶](#redis.Redis.pubsub_numpat "Permalink to this definition")

Returns the number of subscriptions to patterns

pubsub\_numsub(*\*args*)[[source]](_modules/redis/client.html#Redis.pubsub_numsub)[¶](#redis.Redis.pubsub_numsub "Permalink to this definition")

Return a list of (channel, number of subscribers) tuples

for each channel given in `\*args`

randomkey()[[source]](_modules/redis/client.html#Redis.randomkey)[¶](#redis.Redis.randomkey "Permalink to this definition")

Returns the name of a random key

readonly()[[source]](_modules/redis/client.html#Redis.readonly)[¶](#redis.Redis.readonly "Permalink to this definition")

Enables read queries for a connection to a Redis Cluster replica node

readwrite()[[source]](_modules/redis/client.html#Redis.readwrite)[¶](#redis.Redis.readwrite "Permalink to this definition")

Disables read queries for a connection to a Redis Cluster slave node

register\_script(*script*)[[source]](_modules/redis/client.html#Redis.register_script)[¶](#redis.Redis.register_script "Permalink to this definition")

Register a Lua `script` specifying the `keys` it will touch.

Returns a Script object that is callable and hides the complexity of

deal with scripts, keys, and shas. This is the preferred way to work

with Lua scripts.

rename(*src*, *dst*)[[source]](_modules/redis/client.html#Redis.rename)[¶](#redis.Redis.rename "Permalink to this definition")

Rename key `src` to `dst`

renamenx(*src*, *dst*)[[source]](_modules/redis/client.html#Redis.renamenx)[¶](#redis.Redis.renamenx "Permalink to this definition")

Rename key `src` to `dst` if `dst` doesn’t already exist

restore(*name*, *ttl*, *value*, *replace=False*)[[source]](_modules/redis/client.html#Redis.restore)[¶](#redis.Redis.restore "Permalink to this definition")

Create a key using the provided serialized value, previously obtained

using DUMP.

rpop(*name*)[[source]](_modules/redis/client.html#Redis.rpop)[¶](#redis.Redis.rpop "Permalink to this definition")

Remove and return the last item of the list `name`

rpoplpush(*src*, *dst*)[[source]](_modules/redis/client.html#Redis.rpoplpush)[¶](#redis.Redis.rpoplpush "Permalink to this definition")

RPOP a value off of the `src` list and atomically LPUSH it

on to the `dst` list. Returns the value.

rpush(*name*, *\*values*)[[source]](_modules/redis/client.html#Redis.rpush)[¶](#redis.Redis.rpush "Permalink to this definition")

Push `values` onto the tail of the list `name`

rpushx(*name*, *value*)[[source]](_modules/redis/client.html#Redis.rpushx)[¶](#redis.Redis.rpushx "Permalink to this definition")

Push `value` onto the tail of the list `name` if `name` exists

sadd(*name*, *\*values*)[[source]](_modules/redis/client.html#Redis.sadd)[¶](#redis.Redis.sadd "Permalink to this definition")

Add `value(s)` to set `name`

save()[[source]](_modules/redis/client.html#Redis.save)[¶](#redis.Redis.save "Permalink to this definition")

Tell the Redis server to save its data to disk,

blocking until the save is complete

scan(*cursor=0*, *match=None*, *count=None*, *\_type=None*)[[source]](_modules/redis/client.html#Redis.scan)[¶](#redis.Redis.scan "Permalink to this definition")

Incrementally return lists of key names. Also return a cursor

indicating the scan position.

`match` allows for filtering the keys by pattern

`count` provides a hint to Redis about the number of keys toreturn per batch.

`\_type` filters the returned values by a particular Redis type.Stock Redis instances allow for the following types:

HASH, LIST, SET, STREAM, STRING, ZSET

Additionally, Redis modules can expose other types as well.

scan\_iter(*match=None*, *count=None*, *\_type=None*)[[source]](_modules/redis/client.html#Redis.scan_iter)[¶](#redis.Redis.scan_iter "Permalink to this definition")

Make an iterator using the SCAN command so that the client doesn’t

need to remember the cursor position.

`match` allows for filtering the keys by pattern

`count` provides a hint to Redis about the number of keys toreturn per batch.

`\_type` filters the returned values by a particular Redis type.Stock Redis instances allow for the following types:

HASH, LIST, SET, STREAM, STRING, ZSET

Additionally, Redis modules can expose other types as well.

scard(*name*)[[source]](_modules/redis/client.html#Redis.scard)[¶](#redis.Redis.scard "Permalink to this definition")

Return the number of elements in set `name`

script\_exists(*\*args*)[[source]](_modules/redis/client.html#Redis.script_exists)[¶](#redis.Redis.script_exists "Permalink to this definition")

Check if a script exists in the script cache by specifying the SHAs of

each script as `args`. Returns a list of boolean values indicating if

if each already script exists in the cache.

script\_flush()[[source]](_modules/redis/client.html#Redis.script_flush)[¶](#redis.Redis.script_flush "Permalink to this definition")

Flush all scripts from the script cache

script\_kill()[[source]](_modules/redis/client.html#Redis.script_kill)[¶](#redis.Redis.script_kill "Permalink to this definition")

Kill the currently executing Lua script

script\_load(*script*)[[source]](_modules/redis/client.html#Redis.script_load)[¶](#redis.Redis.script_load "Permalink to this definition")

Load a Lua `script` into the script cache. Returns the SHA.

sdiff(*keys*, *\*args*)[[source]](_modules/redis/client.html#Redis.sdiff)[¶](#redis.Redis.sdiff "Permalink to this definition")

Return the difference of sets specified by `keys`

sdiffstore(*dest*, *keys*, *\*args*)[[source]](_modules/redis/client.html#Redis.sdiffstore)[¶](#redis.Redis.sdiffstore "Permalink to this definition")

Store the difference of sets specified by `keys` into a new

set named `dest`. Returns the number of keys in the new set.

sentinel(*\*args*)[[source]](_modules/redis/client.html#Redis.sentinel)[¶](#redis.Redis.sentinel "Permalink to this definition")

Redis Sentinel’s SENTINEL command.

sentinel\_get\_master\_addr\_by\_name(*service\_name*)[[source]](_modules/redis/client.html#Redis.sentinel_get_master_addr_by_name)[¶](#redis.Redis.sentinel_get_master_addr_by_name "Permalink to this definition")

Returns a (host, port) pair for the given `service\_name`

sentinel\_master(*service\_name*)[[source]](_modules/redis/client.html#Redis.sentinel_master)[¶](#redis.Redis.sentinel_master "Permalink to this definition")

Returns a dictionary containing the specified masters state.

sentinel\_masters()[[source]](_modules/redis/client.html#Redis.sentinel_masters)[¶](#redis.Redis.sentinel_masters "Permalink to this definition")

Returns a list of dictionaries containing each master’s state.

sentinel\_monitor(*name*, *ip*, *port*, *quorum*)[[source]](_modules/redis/client.html#Redis.sentinel_monitor)[¶](#redis.Redis.sentinel_monitor "Permalink to this definition")

Add a new master to Sentinel to be monitored

sentinel\_remove(*name*)[[source]](_modules/redis/client.html#Redis.sentinel_remove)[¶](#redis.Redis.sentinel_remove "Permalink to this definition")

Remove a master from Sentinel’s monitoring

sentinel\_sentinels(*service\_name*)[[source]](_modules/redis/client.html#Redis.sentinel_sentinels)[¶](#redis.Redis.sentinel_sentinels "Permalink to this definition")

Returns a list of sentinels for `service\_name`

sentinel\_set(*name*, *option*, *value*)[[source]](_modules/redis/client.html#Redis.sentinel_set)[¶](#redis.Redis.sentinel_set "Permalink to this definition")

Set Sentinel monitoring parameters for a given master

sentinel\_slaves(*service\_name*)[[source]](_modules/redis/client.html#Redis.sentinel_slaves)[¶](#redis.Redis.sentinel_slaves "Permalink to this definition")

Returns a list of slaves for `service\_name`

set(*name*, *value*, *ex=None*, *px=None*, *nx=False*, *xx=False*, *keepttl=False*)[[source]](_modules/redis/client.html#Redis.set)[¶](#redis.Redis.set "Permalink to this definition")

Set the value at key `name` to `value`

`ex` sets an expire flag on key `name` for `ex` seconds.

`px` sets an expire flag on key `name` for `px` milliseconds.

`nx` if set to True, set the value at key `name` to `value` onlyif it does not exist.

`xx` if set to True, set the value at key `name` to `value` onlyif it already exists.

`keepttl` if True, retain the time to live associated with the key.(Available since Redis 6.0)

set\_response\_callback(*command*, *callback*)[[source]](_modules/redis/client.html#Redis.set_response_callback)[¶](#redis.Redis.set_response_callback "Permalink to this definition")

Set a custom Response Callback

setbit(*name*, *offset*, *value*)[[source]](_modules/redis/client.html#Redis.setbit)[¶](#redis.Redis.setbit "Permalink to this definition")

Flag the `offset` in `name` as `value`. Returns a boolean

indicating the previous value of `offset`.

setex(*name*, *time*, *value*)[[source]](_modules/redis/client.html#Redis.setex)[¶](#redis.Redis.setex "Permalink to this definition")

Set the value of key `name` to `value` that expires in `time`

seconds. `time` can be represented by an integer or a Python

timedelta object.

setnx(*name*, *value*)[[source]](_modules/redis/client.html#Redis.setnx)[¶](#redis.Redis.setnx "Permalink to this definition")

Set the value of key `name` to `value` if key doesn’t exist

setrange(*name*, *offset*, *value*)[[source]](_modules/redis/client.html#Redis.setrange)[¶](#redis.Redis.setrange "Permalink to this definition")

Overwrite bytes in the value of `name` starting at `offset` with

`value`. If `offset` plus the length of `value` exceeds the

length of the original value, the new value will be larger than before.

If `offset` exceeds the length of the original value, null bytes

will be used to pad between the end of the previous value and the start

of what’s being injected.

Returns the length of the new string.

shutdown(*save=False*, *nosave=False*)[[source]](_modules/redis/client.html#Redis.shutdown)[¶](#redis.Redis.shutdown "Permalink to this definition")

Shutdown the Redis server. If Redis has persistence configured,

data will be flushed before shutdown. If the “save” option is set,

a data flush will be attempted even if there is no persistence

configured. If the “nosave” option is set, no data flush will be

attempted. The “save” and “nosave” options cannot both be set.

sinter(*keys*, *\*args*)[[source]](_modules/redis/client.html#Redis.sinter)[¶](#redis.Redis.sinter "Permalink to this definition")

Return the intersection of sets specified by `keys`

sinterstore(*dest*, *keys*, *\*args*)[[source]](_modules/redis/client.html#Redis.sinterstore)[¶](#redis.Redis.sinterstore "Permalink to this definition")

Store the intersection of sets specified by `keys` into a new

set named `dest`. Returns the number of keys in the new set.

sismember(*name*, *value*)[[source]](_modules/redis/client.html#Redis.sismember)[¶](#redis.Redis.sismember "Permalink to this definition")

Return a boolean indicating if `value` is a member of set `name`

slaveof(*host=None*, *port=None*)[[source]](_modules/redis/client.html#Redis.slaveof)[¶](#redis.Redis.slaveof "Permalink to this definition")

Set the server to be a replicated slave of the instance identified

by the `host` and `port`. If called without arguments, the

instance is promoted to a master instead.

slowlog\_get(*num=None*)[[source]](_modules/redis/client.html#Redis.slowlog_get)[¶](#redis.Redis.slowlog_get "Permalink to this definition")

Get the entries from the slowlog. If `num` is specified, get the

most recent `num` items.

slowlog\_len()[[source]](_modules/redis/client.html#Redis.slowlog_len)[¶](#redis.Redis.slowlog_len "Permalink to this definition")

Get the number of items in the slowlog

slowlog\_reset()[[source]](_modules/redis/client.html#Redis.slowlog_reset)[¶](#redis.Redis.slowlog_reset "Permalink to this definition")

Remove all items in the slowlog

smembers(*name*)[[source]](_modules/redis/client.html#Redis.smembers)[¶](#redis.Redis.smembers "Permalink to this definition")

Return all members of the set `name`

smove(*src*, *dst*, *value*)[[source]](_modules/redis/client.html#Redis.smove)[¶](#redis.Redis.smove "Permalink to this definition")

Move `value` from set `src` to set `dst` atomically

sort(*name*, *start=None*, *num=None*, *by=None*, *get=None*, *desc=False*, *alpha=False*, *store=None*, *groups=False*)[[source]](_modules/redis/client.html#Redis.sort)[¶](#redis.Redis.sort "Permalink to this definition")

Sort and return the list, set or sorted set at `name`.

`start` and `num` allow for paging through the sorted data

`by` allows using an external key to weight and sort the items.Use an “\*” to indicate where in the key the item value is located

`get` allows for returning items from external keys rather than thesorted data itself. Use an “\*” to indicate where in the key

the item value is located

`desc` allows for reversing the sort

`alpha` allows for sorting lexicographically rather than numerically

`store` allows for storing the result of the sort intothe key `store`

`groups` if set to True and if `get` contains at least twoelements, sort will return a list of tuples, each containing the

values fetched from the arguments to `get`.

spop(*name*, *count=None*)[[source]](_modules/redis/client.html#Redis.spop)[¶](#redis.Redis.spop "Permalink to this definition")

Remove and return a random member of set `name`

srandmember(*name*, *number=None*)[[source]](_modules/redis/client.html#Redis.srandmember)[¶](#redis.Redis.srandmember "Permalink to this definition")

If `number` is None, returns a random member of set `name`.

If `number` is supplied, returns a list of `number` random

members of set `name`. Note this is only available when running

Redis 2.6+.

srem(*name*, *\*values*)[[source]](_modules/redis/client.html#Redis.srem)[¶](#redis.Redis.srem "Permalink to this definition")

Remove `values` from set `name`

sscan(*name*, *cursor=0*, *match=None*, *count=None*)[[source]](_modules/redis/client.html#Redis.sscan)[¶](#redis.Redis.sscan "Permalink to this definition")

Incrementally return lists of elements in a set. Also return a cursor

indicating the scan position.

`match` allows for filtering the keys by pattern

`count` allows for hint the minimum number of returns

sscan\_iter(*name*, *match=None*, *count=None*)[[source]](_modules/redis/client.html#Redis.sscan_iter)[¶](#redis.Redis.sscan_iter "Permalink to this definition")

Make an iterator using the SSCAN command so that the client doesn’t

need to remember the cursor position.

`match` allows for filtering the keys by pattern

`count` allows for hint the minimum number of returns

strlen(*name*)[[source]](_modules/redis/client.html#Redis.strlen)[¶](#redis.Redis.strlen "Permalink to this definition")

Return the number of bytes stored in the value of `name`

substr(*name*, *start*, *end=- 1*)[[source]](_modules/redis/client.html#Redis.substr)[¶](#redis.Redis.substr "Permalink to this definition")

Return a substring of the string at key `name`. `start` and `end`

are 0-based integers specifying the portion of the string to return.

sunion(*keys*, *\*args*)[[source]](_modules/redis/client.html#Redis.sunion)[¶](#redis.Redis.sunion "Permalink to this definition")

Return the union of sets specified by `keys`

sunionstore(*dest*, *keys*, *\*args*)[[source]](_modules/redis/client.html#Redis.sunionstore)[¶](#redis.Redis.sunionstore "Permalink to this definition")

Store the union of sets specified by `keys` into a new

set named `dest`. Returns the number of keys in the new set.

swapdb(*first*, *second*)[[source]](_modules/redis/client.html#Redis.swapdb)[¶](#redis.Redis.swapdb "Permalink to this definition")

Swap two databases

time()[[source]](_modules/redis/client.html#Redis.time)[¶](#redis.Redis.time "Permalink to this definition")

Returns the server time as a 2-item tuple of ints:

(seconds since epoch, microseconds into this second).

touch(*\*args*)[[source]](_modules/redis/client.html#Redis.touch)[¶](#redis.Redis.touch "Permalink to this definition")

Alters the last access time of a key(s) `\*args`. A key is ignored

if it does not exist.

transaction(*func*, *\*watches*, *\*\*kwargs*)[[source]](_modules/redis/client.html#Redis.transaction)[¶](#redis.Redis.transaction "Permalink to this definition")

Convenience method for executing the callable func as a transaction

while watching all keys specified in watches. The ‘func’ callable

should expect a single argument which is a Pipeline object.

ttl(*name*)[[source]](_modules/redis/client.html#Redis.ttl)[¶](#redis.Redis.ttl "Permalink to this definition")

Returns the number of seconds until the key `name` will expire

type(*name*)[[source]](_modules/redis/client.html#Redis.type)[¶](#redis.Redis.type "Permalink to this definition")

Returns the type of key `name`

unlink(*\*names*)[[source]](_modules/redis/client.html#Redis.unlink)[¶](#redis.Redis.unlink "Permalink to this definition")

Unlink one or more keys specified by `names`

unwatch()[[source]](_modules/redis/client.html#Redis.unwatch)[¶](#redis.Redis.unwatch "Permalink to this definition")

Unwatches the value at key `name`, or None of the key doesn’t exist

wait(*num\_replicas*, *timeout*)[[source]](_modules/redis/client.html#Redis.wait)[¶](#redis.Redis.wait "Permalink to this definition")

Redis synchronous replication

That returns the number of replicas that processed the query when

we finally have at least `num\_replicas`, or when the `timeout` was

reached.

watch(*\*names*)[[source]](_modules/redis/client.html#Redis.watch)[¶](#redis.Redis.watch "Permalink to this definition")

Watches the values at keys `names`, or None if the key doesn’t exist

xack(*name*, *groupname*, *\*ids*)[[source]](_modules/redis/client.html#Redis.xack)[¶](#redis.Redis.xack "Permalink to this definition")

Acknowledges the successful processing of one or more messages.

name: name of the stream.

groupname: name of the consumer group.

[\*](#id3)ids: message ids to acknowlege.

xadd(*name*, *fields*, *id='\*'*, *maxlen=None*, *approximate=True*)[[source]](_modules/redis/client.html#Redis.xadd)[¶](#redis.Redis.xadd "Permalink to this definition")

Add to a stream.

name: name of the stream

fields: dict of field/value pairs to insert into the stream

id: Location to insert this record. By default it is appended.

maxlen: truncate old stream members beyond this size

approximate: actual stream length may be slightly more than maxlen

xclaim(*name*, *groupname*, *consumername*, *min\_idle\_time*, *message\_ids*, *idle=None*, *time=None*, *retrycount=None*, *force=False*, *justid=False*)[[source]](_modules/redis/client.html#Redis.xclaim)[¶](#redis.Redis.xclaim "Permalink to this definition")

Changes the ownership of a pending message.

name: name of the stream.

groupname: name of the consumer group.

consumername: name of a consumer that claims the message.

min\_idle\_time: filter messages that were idle less than this amount of

milliseconds

message\_ids: non-empty list or tuple of message IDs to claim

idle: optional. Set the idle time (last time it was delivered) of the

> 

> message in ms

> 

> 

> 

time: optional integer. This is the same as idle but instead of arelative amount of milliseconds, it sets the idle time to a specific

Unix time (in milliseconds).

retrycount: optional integer. set the retry counter to the specifiedvalue. This counter is incremented every time a message is delivered

again.

force: optional boolean, false by default. Creates the pending messageentry in the PEL even if certain specified IDs are not already in the

PEL assigned to a different client.

justid: optional boolean, false by default. Return just an array of IDsof messages successfully claimed, without returning the actual message

xdel(*name*, *\*ids*)[[source]](_modules/redis/client.html#Redis.xdel)[¶](#redis.Redis.xdel "Permalink to this definition")

Deletes one or more messages from a stream.

name: name of the stream.

[\*](#id5)ids: message ids to delete.

xgroup\_create(*name*, *groupname*, *id='$'*, *mkstream=False*)[[source]](_modules/redis/client.html#Redis.xgroup_create)[¶](#redis.Redis.xgroup_create "Permalink to this definition")

Create a new consumer group associated with a stream.

name: name of the stream.

groupname: name of the consumer group.

id: ID of the last item in the stream to consider already delivered.

xgroup\_delconsumer(*name*, *groupname*, *consumername*)[[source]](_modules/redis/client.html#Redis.xgroup_delconsumer)[¶](#redis.Redis.xgroup_delconsumer "Permalink to this definition")

Remove a specific consumer from a consumer group.

Returns the number of pending messages that the consumer had before it

was deleted.

name: name of the stream.

groupname: name of the consumer group.

consumername: name of consumer to delete

xgroup\_destroy(*name*, *groupname*)[[source]](_modules/redis/client.html#Redis.xgroup_destroy)[¶](#redis.Redis.xgroup_destroy "Permalink to this definition")

Destroy a consumer group.

name: name of the stream.

groupname: name of the consumer group.

xgroup\_setid(*name*, *groupname*, *id*)[[source]](_modules/redis/client.html#Redis.xgroup_setid)[¶](#redis.Redis.xgroup_setid "Permalink to this definition")

Set the consumer group last delivered ID to something else.

name: name of the stream.

groupname: name of the consumer group.

id: ID of the last item in the stream to consider already delivered.

xinfo\_consumers(*name*, *groupname*)[[source]](_modules/redis/client.html#Redis.xinfo_consumers)[¶](#redis.Redis.xinfo_consumers "Permalink to this definition")

Returns general information about the consumers in the group.

name: name of the stream.

groupname: name of the consumer group.

xinfo\_groups(*name*)[[source]](_modules/redis/client.html#Redis.xinfo_groups)[¶](#redis.Redis.xinfo_groups "Permalink to this definition")

Returns general information about the consumer groups of the stream.

name: name of the stream.

xinfo\_stream(*name*)[[source]](_modules/redis/client.html#Redis.xinfo_stream)[¶](#redis.Redis.xinfo_stream "Permalink to this definition")

Returns general information about the stream.

name: name of the stream.

xlen(*name*)[[source]](_modules/redis/client.html#Redis.xlen)[¶](#redis.Redis.xlen "Permalink to this definition")

Returns the number of elements in a given stream.

xpending(*name*, *groupname*)[[source]](_modules/redis/client.html#Redis.xpending)[¶](#redis.Redis.xpending "Permalink to this definition")

Returns information about pending messages of a group.

name: name of the stream.

groupname: name of the consumer group.

xpending\_range(*name*, *groupname*, *min*, *max*, *count*, *consumername=None*)[[source]](_modules/redis/client.html#Redis.xpending_range)[¶](#redis.Redis.xpending_range "Permalink to this definition")

Returns information about pending messages, in a range.

name: name of the stream.

groupname: name of the consumer group.

min: minimum stream ID.

max: maximum stream ID.

count: number of messages to return

consumername: name of a consumer to filter by (optional).

xrange(*name*, *min='-'*, *max='+'*, *count=None*)[[source]](_modules/redis/client.html#Redis.xrange)[¶](#redis.Redis.xrange "Permalink to this definition")

Read stream values within an interval.

name: name of the stream.

start: first stream ID. defaults to ‘-‘,

> 

> meaning the earliest available.

> 

> 

> 

finish: last stream ID. defaults to ‘+’,meaning the latest available.

count: if set, only return this many items, beginning with theearliest available.

xread(*streams*, *count=None*, *block=None*)[[source]](_modules/redis/client.html#Redis.xread)[¶](#redis.Redis.xread "Permalink to this definition")

Block and monitor multiple streams for new data.

streams: a dict of stream names to stream IDs, where

> 

> IDs indicate the last ID already seen.

> 

> 

> 

count: if set, only return this many items, beginning with theearliest available.

block: number of milliseconds to wait, if nothing already present.

xreadgroup(*groupname*, *consumername*, *streams*, *count=None*, *block=None*, *noack=False*)[[source]](_modules/redis/client.html#Redis.xreadgroup)[¶](#redis.Redis.xreadgroup "Permalink to this definition")

Read from a stream via a consumer group.

groupname: name of the consumer group.

consumername: name of the requesting consumer.

streams: a dict of stream names to stream IDs, where

> 

> IDs indicate the last ID already seen.

> 

> 

> 

count: if set, only return this many items, beginning with theearliest available.

block: number of milliseconds to wait, if nothing already present.

noack: do not add messages to the PEL

xrevrange(*name*, *max='+'*, *min='-'*, *count=None*)[[source]](_modules/redis/client.html#Redis.xrevrange)[¶](#redis.Redis.xrevrange "Permalink to this definition")

Read stream values within an interval, in reverse order.

name: name of the stream

start: first stream ID. defaults to ‘+’,

> 

> meaning the latest available.

> 

> 

> 

finish: last stream ID. defaults to ‘-‘,meaning the earliest available.

count: if set, only return this many items, beginning with thelatest available.

xtrim(*name*, *maxlen*, *approximate=True*)[[source]](_modules/redis/client.html#Redis.xtrim)[¶](#redis.Redis.xtrim "Permalink to this definition")

Trims old messages from a stream.

name: name of the stream.

maxlen: truncate old stream messages beyond this size

approximate: actual stream length may be slightly more than maxlen

zadd(*name*, *mapping*, *nx=False*, *xx=False*, *ch=False*, *incr=False*)[[source]](_modules/redis/client.html#Redis.zadd)[¶](#redis.Redis.zadd "Permalink to this definition")

Set any number of element-name, score pairs to the key `name`. Pairs

are specified as a dict of element-names keys to score values.

`nx` forces ZADD to only create new elements and not to update

scores for elements that already exist.

`xx` forces ZADD to only update scores of elements that already

exist. New elements will not be added.

`ch` modifies the return value to be the numbers of elements changed.

Changed elements include new elements that were added and elements

whose scores changed.

`incr` modifies ZADD to behave like ZINCRBY. In this mode only a

single element/score pair can be specified and the score is the amount

the existing score will be incremented by. When using this mode the

return value of ZADD will be the new score of the element.

The return value of ZADD varies based on the mode specified. With no

options, ZADD returns the number of new elements added to the sorted

set.

zcard(*name*)[[source]](_modules/redis/client.html#Redis.zcard)[¶](#redis.Redis.zcard "Permalink to this definition")

Return the number of elements in the sorted set `name`

zcount(*name*, *min*, *max*)[[source]](_modules/redis/client.html#Redis.zcount)[¶](#redis.Redis.zcount "Permalink to this definition")

Returns the number of elements in the sorted set at key `name` with

a score between `min` and `max`.

zincrby(*name*, *amount*, *value*)[[source]](_modules/redis/client.html#Redis.zincrby)[¶](#redis.Redis.zincrby "Permalink to this definition")

Increment the score of `value` in sorted set `name` by `amount`

zinterstore(*dest*, *keys*, *aggregate=None*)[[source]](_modules/redis/client.html#Redis.zinterstore)[¶](#redis.Redis.zinterstore "Permalink to this definition")

Intersect multiple sorted sets specified by `keys` into

a new sorted set, `dest`. Scores in the destination will be

aggregated based on the `aggregate`, or SUM if none is provided.

zlexcount(*name*, *min*, *max*)[[source]](_modules/redis/client.html#Redis.zlexcount)[¶](#redis.Redis.zlexcount "Permalink to this definition")

Return the number of items in the sorted set `name` between the

lexicographical range `min` and `max`.

zpopmax(*name*, *count=None*)[[source]](_modules/redis/client.html#Redis.zpopmax)[¶](#redis.Redis.zpopmax "Permalink to this definition")

Remove and return up to `count` members with the highest scores

from the sorted set `name`.

zpopmin(*name*, *count=None*)[[source]](_modules/redis/client.html#Redis.zpopmin)[¶](#redis.Redis.zpopmin "Permalink to this definition")

Remove and return up to `count` members with the lowest scores

from the sorted set `name`.

zrange(*name*, *start*, *end*, *desc=False*, *withscores=False*, *score\_cast\_func=<class 'float'>*)[[source]](_modules/redis/client.html#Redis.zrange)[¶](#redis.Redis.zrange "Permalink to this definition")

Return a range of values from sorted set `name` between

`start` and `end` sorted in ascending order.

`start` and `end` can be negative, indicating the end of the range.

`desc` a boolean indicating whether to sort the results descendingly

`withscores` indicates to return the scores along with the values.

The return type is a list of (value, score) pairs

`score\_cast\_func` a callable used to cast the score return value

zrangebylex(*name*, *min*, *max*, *start=None*, *num=None*)[[source]](_modules/redis/client.html#Redis.zrangebylex)[¶](#redis.Redis.zrangebylex "Permalink to this definition")

Return the lexicographical range of values from sorted set `name`

between `min` and `max`.

If `start` and `num` are specified, then return a slice of the

range.

zrangebyscore(*name*, *min*, *max*, *start=None*, *num=None*, *withscores=False*, *score\_cast\_func=<class 'float'>*)[[source]](_modules/redis/client.html#Redis.zrangebyscore)[¶](#redis.Redis.zrangebyscore "Permalink to this definition")

Return a range of values from the sorted set `name` with scores

between `min` and `max`.

If `start` and `num` are specified, then return a slice

of the range.

`withscores` indicates to return the scores along with the values.

The return type is a list of (value, score) pairs

score\_cast\_func` a callable used to cast the score return value

zrank(*name*, *value*)[[source]](_modules/redis/client.html#Redis.zrank)[¶](#redis.Redis.zrank "Permalink to this definition")

Returns a 0-based value indicating the rank of `value` in sorted set

`name`

zrem(*name*, *\*values*)[[source]](_modules/redis/client.html#Redis.zrem)[¶](#redis.Redis.zrem "Permalink to this definition")

Remove member `values` from sorted set `name`

zremrangebylex(*name*, *min*, *max*)[[source]](_modules/redis/client.html#Redis.zremrangebylex)[¶](#redis.Redis.zremrangebylex "Permalink to this definition")

Remove all elements in the sorted set `name` between the

lexicographical range specified by `min` and `max`.

Returns the number of elements removed.

zremrangebyrank(*name*, *min*, *max*)[[source]](_modules/redis/client.html#Redis.zremrangebyrank)[¶](#redis.Redis.zremrangebyrank "Permalink to this definition")

Remove all elements in the sorted set `name` with ranks between

`min` and `max`. Values are 0-based, ordered from smallest score

to largest. Values can be negative indicating the highest scores.

Returns the number of elements removed

zremrangebyscore(*name*, *min*, *max*)[[source]](_modules/redis/client.html#Redis.zremrangebyscore)[¶](#redis.Redis.zremrangebyscore "Permalink to this definition")

Remove all elements in the sorted set `name` with scores

between `min` and `max`. Returns the number of elements removed.

zrevrange(*name*, *start*, *end*, *withscores=False*, *score\_cast\_func=<class 'float'>*)[[source]](_modules/redis/client.html#Redis.zrevrange)[¶](#redis.Redis.zrevrange "Permalink to this definition")

Return a range of values from sorted set `name` between

`start` and `end` sorted in descending order.

`start` and `end` can be negative, indicating the end of the range.

`withscores` indicates to return the scores along with the values

The return type is a list of (value, score) pairs

`score\_cast\_func` a callable used to cast the score return value

zrevrangebylex(*name*, *max*, *min*, *start=None*, *num=None*)[[source]](_modules/redis/client.html#Redis.zrevrangebylex)[¶](#redis.Redis.zrevrangebylex "Permalink to this definition")

Return the reversed lexicographical range of values from sorted set

`name` between `max` and `min`.

If `start` and `num` are specified, then return a slice of the

range.

zrevrangebyscore(*name*, *max*, *min*, *start=None*, *num=None*, *withscores=False*, *score\_cast\_func=<class 'float'>*)[[source]](_modules/redis/client.html#Redis.zrevrangebyscore)[¶](#redis.Redis.zrevrangebyscore "Permalink to this definition")

Return a range of values from the sorted set `name` with scores

between `min` and `max` in descending order.

If `start` and `num` are specified, then return a slice

of the range.

`withscores` indicates to return the scores along with the values.

The return type is a list of (value, score) pairs

`score\_cast\_func` a callable used to cast the score return value

zrevrank(*name*, *value*)[[source]](_modules/redis/client.html#Redis.zrevrank)[¶](#redis.Redis.zrevrank "Permalink to this definition")

Returns a 0-based value indicating the descending rank of

`value` in sorted set `name`

zscan(*name*, *cursor=0*, *match=None*, *count=None*, *score\_cast\_func=<class 'float'>*)[[source]](_modules/redis/client.html#Redis.zscan)[¶](#redis.Redis.zscan "Permalink to this definition")

Incrementally return lists of elements in a sorted set. Also return a

cursor indicating the scan position.

`match` allows for filtering the keys by pattern

`count` allows for hint the minimum number of returns

`score\_cast\_func` a callable used to cast the score return value

zscan\_iter(*name*, *match=None*, *count=None*, *score\_cast\_func=<class 'float'>*)[[source]](_modules/redis/client.html#Redis.zscan_iter)[¶](#redis.Redis.zscan_iter "Permalink to this definition")

Make an iterator using the ZSCAN command so that the client doesn’t

need to remember the cursor position.

`match` allows for filtering the keys by pattern

`count` allows for hint the minimum number of returns

`score\_cast\_func` a callable used to cast the score return value

zscore(*name*, *value*)[[source]](_modules/redis/client.html#Redis.zscore)[¶](#redis.Redis.zscore "Permalink to this definition")

Return the score of element `value` in sorted set `name`

zunionstore(*dest*, *keys*, *aggregate=None*)[[source]](_modules/redis/client.html#Redis.zunionstore)[¶](#redis.Redis.zunionstore "Permalink to this definition")

Union multiple sorted sets specified by `keys` into

a new sorted set, `dest`. Scores in the destination will be

aggregated based on the `aggregate`, or SUM if none is provided.

*exception* redis.RedisError[[source]](_modules/redis/exceptions.html#RedisError)[¶](#redis.RedisError "Permalink to this definition")

*exception* redis.ResponseError[[source]](_modules/redis/exceptions.html#ResponseError)[¶](#redis.ResponseError "Permalink to this definition")

*class* redis.SSLConnection(*ssl\_keyfile=None*, *ssl\_certfile=None*, *ssl\_cert\_reqs='required'*, *ssl\_ca\_certs=None*, *ssl\_check\_hostname=False*, *\*\*kwargs*)[[source]](_modules/redis/connection.html#SSLConnection)[¶](#redis.SSLConnection "Permalink to this definition")

redis.StrictRedis[¶](#redis.StrictRedis "Permalink to this definition")

alias of [`redis.client.Redis`](#redis.Redis "redis.client.Redis")

*exception* redis.TimeoutError[[source]](_modules/redis/exceptions.html#TimeoutError)[¶](#redis.TimeoutError "Permalink to this definition")

*class* redis.UnixDomainSocketConnection(*path=''*, *db=0*, *username=None*, *password=None*, *socket\_timeout=None*, *encoding='utf-8'*, *encoding\_errors='strict'*, *decode\_responses=False*, *retry\_on\_timeout=False*, *parser\_class=<class 'redis.connection.PythonParser'>*, *socket\_read\_size=65536*, *health\_check\_interval=0*, *client\_name=None*)[[source]](_modules/redis/connection.html#UnixDomainSocketConnection)[¶](#redis.UnixDomainSocketConnection "Permalink to this definition")

*exception* redis.WatchError[[source]](_modules/redis/exceptions.html#WatchError)[¶](#redis.WatchError "Permalink to this definition")

redis.from\_url(*url*, *db=None*, *\*\*kwargs*)[[source]](_modules/redis/utils.html#from_url)[¶](#redis.from_url "Permalink to this definition")

Returns an active Redis client generated from the given database URL.

Will attempt to extract the database id from the path url fragment, if

none is provided.

