Implementation of the Redis protocol. This abstract class provides a Python interface to all Redis commands and an implementation of the Redis protocol. Pipelines derive from this, implementing how the commands are sent and received to the Redis server. Based on configurat
| 145 | |
| 146 | |
| 147 | class Redis(RedisModuleCommands, CoreCommands, SentinelCommands): |
| 148 | """ |
| 149 | Implementation of the Redis protocol. |
| 150 | |
| 151 | This abstract class provides a Python interface to all Redis commands |
| 152 | and an implementation of the Redis protocol. |
| 153 | |
| 154 | Pipelines derive from this, implementing how |
| 155 | the commands are sent and received to the Redis server. Based on |
| 156 | configuration, an instance will either use a ConnectionPool, or |
| 157 | Connection object to talk to redis. |
| 158 | |
| 159 | It is not safe to pass PubSub or Pipeline objects between threads. |
| 160 | """ |
| 161 | |
| 162 | # Type discrimination marker for @overload self-type pattern |
| 163 | _is_async_client: Literal[False] = False |
| 164 | |
| 165 | @classmethod |
| 166 | def from_url(cls, url: str, **kwargs) -> "Redis": |
| 167 | """ |
| 168 | Return a Redis client object configured from the given URL |
| 169 | |
| 170 | For example:: |
| 171 | |
| 172 | redis://[[username]:[password]]@localhost:6379/0 |
| 173 | rediss://[[username]:[password]]@localhost:6379/0 |
| 174 | unix://[username@]/path/to/socket.sock?db=0[&password=password] |
| 175 | |
| 176 | Three URL schemes are supported: |
| 177 | |
| 178 | - `redis://` creates a TCP socket connection. See more at: |
| 179 | <https://www.iana.org/assignments/uri-schemes/prov/redis> |
| 180 | - `rediss://` creates a SSL wrapped TCP socket connection. See more at: |
| 181 | <https://www.iana.org/assignments/uri-schemes/prov/rediss> |
| 182 | - ``unix://``: creates a Unix Domain Socket connection. |
| 183 | |
| 184 | The username, password, hostname, path and all querystring values |
| 185 | are passed through urllib.parse.unquote in order to replace any |
| 186 | percent-encoded values with their corresponding characters. |
| 187 | |
| 188 | There are several ways to specify a database number. The first value |
| 189 | found will be used: |
| 190 | |
| 191 | 1. A ``db`` querystring option, e.g. redis://localhost?db=0 |
| 192 | 2. If using the redis:// or rediss:// schemes, the path argument |
| 193 | of the url, e.g. redis://localhost/0 |
| 194 | 3. A ``db`` keyword argument to this function. |
| 195 | |
| 196 | If none of these options are specified, the default db=0 is used. |
| 197 | |
| 198 | All querystring options are cast to their appropriate Python types. |
| 199 | Boolean arguments can be specified with string values "True"/"False" |
| 200 | or "Yes"/"No". Values that cannot be properly cast cause a |
| 201 | ``ValueError`` to be raised. Once parsed, the querystring arguments |
| 202 | and keyword arguments are passed to the ``ConnectionPool``'s |
| 203 | class initializer. In the case of conflicting arguments, querystring |
| 204 | arguments always win. |
no outgoing calls