harp_apps.storage.services.redis¶
- class Redis[source]¶
Bases:
RedisInitialize a new Redis client.
To specify a retry policy for specific errors, you have two options:
1. Set the retry_on_error to a list of the error/s to retry on, and you can also set retry to a valid Retry object(in case the default one is not appropriate) - with this approach the retries will be triggered on the default errors specified in the Retry object enriched with the errors specified in retry_on_error.
2. Define a Retry object with configured ‘supported_errors’ and set it to the retry parameter - with this approach you completely redefine the errors on which retries will happen.
retry_on_timeout is deprecated - please include the TimeoutError either in the Retry object or in the retry_on_error list.
When ‘connection_pool’ is provided - the retry configuration of the provided pool will be used.
Args:
- socket_keepalive:
if True, TCP keepalive is enabled for TCP socket connections. Argument is ignored when connection_pool is provided.
- socket_keepalive_options:
mapping of TCP keepalive socket option constants to values, for example {socket.TCP_KEEPIDLE: 30}. If left unspecified, redis-py uses TCP keepalive defaults when socket_keepalive is enabled: idle 30 seconds, interval 5 seconds, and 3 probes. Platform-specific options that are not available are skipped. Pass None or {} to avoid setting additional TCP keepalive options. Argument is ignored when connection_pool is provided.
- classmethod from_url(url, single_connection_client=False, auto_close_connection_pool=None, **kwargs)[source]¶
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@]/path/to/socket.sock?db=0[&password=password]
Three URL schemes are supported:
redis:// creates a TCP socket connection. See more at: <https://www.iana.org/assignments/uri-schemes/prov/redis>
rediss:// creates a SSL wrapped TCP socket connection. See more at: <https://www.iana.org/assignments/uri-schemes/prov/rediss>
unix://: creates a Unix Domain Socket connection.
The username, password, hostname, path and all querystring values are passed through urllib.parse.unquote in order to replace any percent-encoded values with their corresponding characters.
There are several ways to specify a database number. The first value found will be used:
A
dbquerystring option, e.g. redis://localhost?db=0- If using the redis:// or rediss:// schemes, the path argument
of the url, e.g. redis://localhost/0
A
dbkeyword argument to this function.
If none of these options are specified, the default db=0 is used.
All querystring options are cast to their appropriate Python types. Boolean arguments can be specified with string values “True”/”False” or “Yes”/”No”. Values that cannot be properly cast cause a
ValueErrorto be raised. Once parsed, the querystring arguments and keyword arguments are passed to theConnectionPool’s class initializer. In the case of conflicting arguments, querystring arguments always win.