summaryrefslogtreecommitdiff
path: root/redis/connection.py
Commit message (Collapse)AuthorAgeFilesLines
...
* Add warning when hiredis not installed. Recommend installation. (#1621)adiamzn2021-10-191-0/+3
|
* Removing packaging dependency (#1626)Chayim2021-10-191-5/+5
|
* Fix `retry` attribute in UnixDomainSocketConnection (#1604)nbraun-amazon2021-10-141-1/+15
|
* Use Version instead of StrictVersion since distutils is deprecated. (#1552)Karthikeyan Singaravelan2021-08-291-5/+5
|
* Add retry mechanism with backoff (#1494)nbraun-amazon2021-08-181-19/+36
|
* All values within Redis URLs are url-unquoted via default.Andy McCurdy2020-08-151-105/+80
| | | | | | | | Prior versions of redis-py supported this by specifying the ``decode_components`` flag to the ``from_url`` functions. This is now done by default and cannot be disabled. Fixes #589
* Remove support for end-of-life Python 2.7 (#1318)Jon Dufresne2020-08-061-82/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove support for end-of-life Python 2.7 Python 2.7 is end of life. It is no longer receiving bug fixes, including for security issues. Python 2.7 went EOL on 2020-01-01. For additional details on support Python versions, see: Supported: https://devguide.python.org/#status-of-python-branches EOL: https://devguide.python.org/devcycle/#end-of-life-branches Removing support for EOL Pythons will reduce testing and maintenance resources while allowing the library to move towards a modern Python 3 style. Python 2.7 users can continue to use the previous version of redis-py. Was able to simplify the code: - Removed redis._compat module - Removed __future__ imports - Removed object from class definition (all classes are new style) - Removed long (Python 3 unified numeric types) - Removed deprecated __nonzero__ method - Use simpler Python 3 super() syntax - Use unified OSError exception - Use yield from syntax Co-authored-by: Andy McCurdy <andy@andymccurdy.com>
* Fix some documentation formattingJon Banafato2020-07-261-19/+20
| | | | | Fix a few broken links and class references, move a docstring, and fix a code block.
* Support for loading, unloading and listing Redis Modules (#1360)Roey Prat2020-07-131-0/+13
| | | | | | | | | | | * Support for loading, unloading and listing Redis Modules * minor fixes for flake * unit test for module list - only the empty use case * ModuleError should inherit from ResponseError rather than RedisError Co-authored-by: Vamsi Atluri <vamc19@gmail.com>
* SentinelConnectionPool plays better with threaded applications.Andy McCurdy2020-06-011-9/+40
| | | | | | | | | Prevent the pool from closing sockets on connections that are actively in use by other threads when the master address changes. Connections returned to the pool that are still connected to the old master will be disconnected gracefully. Fixes #1345
* Restore try/except in __del__ methodsAndy McCurdy2020-05-201-3/+12
| | | | Fixed #1339
* Tune the locking in ConnectionPool.get_connectionAndy McCurdy2020-05-141-21/+22
| | | | | The lock does not need to be held while waiting for the socket to establish and validate the TCP connection.
* Fix typo (missing space) in exception message (#1334)Jon Dufresne2020-04-281-1/+1
|
* Switch to flake8 for static code analysis (#1328)Jon Dufresne2020-04-161-1/+0
| | | | | | | | | flake8 catches a wider net of mistakes than pycodestyle and is more commonly used by the larger community. For example, it catches unused imports, a few of which existed. These have since been removed. Two "noqa" comments were added. One ignores the _compat.py file as it has a large amount of Python version specific code. The second is in utils.py which intentionally does not use an import.
* Fix str/bytes mixup in PythonParser.read_response() (#1324)Jon Dufresne2020-04-131-12/+11
| | | | | | | | | | | | Calling str() on a bytes object can result in a BytesWarning being emitted and usually indicates a mixup between byte and string handling. Now, in the event of an invalid RESP response, use the repr value of the raw response in the exception message. Can further simplify the bytes/str handling by comparing the first byte as a bytes object instead of converting it to str. The bytes literal is available on all supported Pythons. This removes the need for the compatibility function, byte_to_chr().
* Simplify exception handlers (#1319)Jon Dufresne2020-04-111-10/+7
| | | | | | | | | Use the "as" keyword to capture the exception in a variable instead of sys.exc_info(). Re-raise exception with the bare "raise" syntax. Avoid "# noqa: E722" by catching BaseException, which includes all exceptions including SystemExit.
* Support memoryview encoding/decoding as a no-opCody-G2020-02-241-10/+15
| | | | | | | | | | This allows memoryview instances to be passed to Redis command args that expect strings or bytes. The memoryview instance is sent directly to the socket such that there are zero copies made of the underlying data during command packing. Fixes #1265 Fixes #1285
* expand AUTH fallback support to pre-v6 Redis servers.Andy McCurdy2020-02-121-0/+6
| | | | Ref #1274
* Stop hiding errors that occur inside __del__ methodsJon Dufresne2020-02-121-12/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If an exception occurs inside the __del__ method, it should be reported to the developer. Not doing so could hide bugs. Python automatically handles exceptions inside __del__ methods, for example: class A: def __del__(self): 1 / 0 A() print("after del") Results in the output: $ python3 ~/blah.py Exception ignored in: <function A.__del__ at 0x7fbbf2bbfc20> Traceback (most recent call last): File "/home/jon/test.py", line 3, in __del__ 1 / 0 ZeroDivisionError: division by zero after del From this example, we can see the bug was not hidden and the code after __del__ still executed. fixes #1281
* Drop unused variables and imports (#1284)Jon Dufresne2020-02-121-1/+1
|
* remove Redis and ConnectionPool __eq__ comparisonAndy McCurdy2020-02-011-6/+0
| | | | | | | | | | | | | After further thought this was a bad idea. Just because two connection pools share the same connection arguments does not make them equal. It would seem quite odd if pool_a == pool_b yet pool_a.disconnect() doesn't close all of pool_b's connections. Ref #1240 Fixes #1277 Fixes #1275 Fixes #1267 Fixes #1273
* Move the username argument in the Redis and Connection classes to the endAndy McCurdy2020-01-311-6/+5
| | | | | | | This helps those poor souls that specify all their connection options as non-keyword arguments. Fixes #1276
* Provide AUTH fallback support for connection URLs with a username componentAndy McCurdy2020-01-311-1/+15
| | | | | | | | | | | | | Prior to ACL support, redis-py ignored the username component of Connection URLs. With ACL support, usernames are no longer ignored and are used to authenticate against an ACL rule. Some cloud vendors with managed Redis instances (like Heroku) provide connection URLs with a username component pre-ACL that is not intended to be used. Sending that username to Redis servers < 6.0.0 results in an error. Attempt to detect this condition and retry the AUTH command with only the password such that authentication continues to work for these users. Fixes #1274
* better thread-safety for ConnectionPool (#1270)Andy McCurdy2020-01-301-43/+120
| | | Better thread and fork safety for ConnectionPool and BlockingConnectionPool
* Slight optimization to command packing.Andy McCurdy2019-12-291-3/+4
| | | | Fixed #1255
* Added the 'ssl_check_hostname' option.Andy McCurdy2019-12-291-2/+5
| | | | | | | | 'ssl_check_hostname' tells SSL Connections to whether to require the TCP hostname to match the hostname specified in the SSL Cert. By default 'ssl_check_hostname' is False to maintain backwards compatibility. Fixed #1196
* more accurate description of acceptable argument typesAndy McCurdy2019-12-291-2/+2
| | | | fixes #1214
* Allow setting client_name during connection construction.Peter van Dijk2019-12-291-15/+31
| | | | | | Client instances and Connection pools now accept "client_name" as an optional argument. If supplied, all connections created will be named via CLIENT SETNAME once the connection to the server is established.
* Added support for ACL commandsAndy McCurdy2019-12-281-14/+27
|
* Fix simple typo: recurrsion -> recursionTim Gates2019-12-071-1/+1
| | | | Closes #1252
* Add equality test on Redis client and conn pool (#1240)Rajiv Bakulesh Shah2019-11-111-0/+6
| | | Add equality test on Redis client and connection pool
* Version 3.3.93.3.9Zac Bristow2019-10-101-5/+7
| | | | | | | | | Fixes SSL read timeouts in Python 2.7 The ssl module in Python 2.7 raises timeouts as ssl.SSLError instead of socket.timeout. When these timeouts are encountered, the error will be re-raised as socket.timeout so it is handled appropriately by the connection.
* version 3.3.7, Fixed a socket.error regression introduced in 3.3.03.3.7Andy McCurdy2019-08-131-4/+16
| | | | | | | Prior versions of 3.3.x could potentially raise a raw socket.error (or one of its subclasses) instead of a redis.exceptions.ConnectionError. Fixes #1202
* version 3.3.6, fixed a regression in 3.3.5 with pubsub timeouts3.3.6Andy McCurdy2019-08-061-0/+8
| | | | Fixes #1200
* version 3.3.5, handle socket.timeout errors correctly in Python 2.73.3.5Andy McCurdy2019-08-021-16/+8
| | | | | Fix an issue where socket.timeout errors could be handled by the wrong exception handler in Python 2.7.
* version 3.3.4, more specifically identify nonblocking read errors3.3.4Andy McCurdy2019-07-301-1/+2
| | | | | | | versions 3.3.1, 3.3.2 and 3.3.3 could potentially hide ConnectionErrors on Python 2.7. This change accurately identifies errors by both exception class and errno to determine whether a nonblocking socket can be read
* version 3.3.4, more specifically identify nonblocking read errorsAndy McCurdy2019-07-301-14/+17
| | | | | | | versions 3.3.1, 3.3.2 and 3.3.3 could potentially hide ConnectionErrors on Python 2.7. This change accurately identifies errors by both exception class and errno to determine whether a nonblocking socket can be read
* Version 3.3.3. Accomodate Python 2.7.x versions < 2.7.9.3.3.3Andy McCurdy2019-07-301-2/+2
| | | | | | | | The SSL module includes in Python versions < 2.7.9 does not include the SSLWantReadError or SSLWantWriteError exceptions. As such we can't assume they are present just because the ssl module happens to be installed. Fixes #1197
* Version 3.3.2, SSL Blocking Exceptions don't use errno.EWOULDBLOCK3.3.2Andy McCurdy2019-07-291-3/+4
| | | | Ref #1197
* version 3.3.1, fixed a regression involving SSL and non-blocking sockets3.3.1Andy McCurdy2019-07-291-8/+19
| | | | Fixes #1197
* PING/PONG health checksAndy McCurdy2019-07-281-14/+47
| | | | | | | | | | | | | | | | | | | | | | The `Redis` class and the `ConnectionPool` class now support the "health_check_interval=N" option. By default N=0, which turns off health checks. `N` should be an integer, and when greater than 0, ensures that a health check is performed just before command execution anytime the underlying connection has been idle for more than N seconds. A health check is a full PING/PONG round trip to the Redis server. If a health check encounters a ConnectionError or TimeoutError, the connection is disconnected and reconnected and the health check is retried exactly once. Any error during the retry is raised to the caller. Health check retries are not governed by any other options such as `retry_on_timeout`. In systems where idle times are common, these health checks are the intended way to reconnect to the Redis server without harming any user data. When this option is enabled for PubSub connections, calling `get_message()` or `listen()` will send a health check anytime a message has not been read on the PubSub connection for `health_check_interval` seconds. Users should call `get_message()` or `listen()` at least every `health_check_interval` seconds in order to keep the connection open.
* Use nonblocking sockets instead of selectors for healthy connectionsAndy McCurdy2019-07-091-50/+105
| | | | | | | This replaces the work in 3.2.0 to use nonblocking sockets instead of selectors. Selectors proved to be problematic for some environments including eventlet and gevent. Nonblocking sockets should be available in all environments.
* All authentication-related errors now raise AuthenticationErrorAndy McCurdy2019-06-031-1/+4
| | | | | | | AuthenticationError is now a subclass of ConnectionError, which means the connection will be shut down and cleaned up. Fixes #923
* Pass encoding_errors setting to hiredis (>=1.0.0) (#1162)Brian Candler2019-05-291-0/+4
| | | | | Pass encoding_errors setting to hiredis (>=1.0.0). Fixes #1161
* remove Token class in favor of bytestringremove_tokenAndy McCurdy2019-05-281-46/+7
| | | | | | | The Token class was needed when supporting Python 2.6. Now that we've dropped support for 2.6, we don't need it anymore. Fixes #1066
* Merged the error process of "reading socket error" in two Parser class and ↵vic0202019-04-111-36/+31
| | | | | | | | added "host":"port" to Exception message for easy debug Change-Id: Ifaa3bef0c8daf3dd2c60b143746b75a26c182a88
* make sure the selector is instantiated prior to cleaning it upAndy McCurdy2019-03-181-2/+4
|
* Close the selector on disconnectBruce Merry2019-03-181-0/+2
|
* attempt to provide only healthy connections from the poolAndy McCurdy2019-02-041-3/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | Adds redis.selector, a module that provides the best selector strategy available on the current platform. A redis.selector polls a socket to provide two pieces of functionality: 1. Check whether data can be read from the socket. Prior versions of redis-py provided this behavior with just select.select(). select() has lots of limitations, most notably a limit of ~1024 file descriptors. Now that better selectors are available, this should make can_read() faster and able to accomodate more clients. See #1115 and #486 2. Check whether a socket is ready for a command to be sent. This doubles as a health check. It ensures that the socket is available for writing, has no data to read and has no known errors. Anytime a socket is disconnected or hung up, data is available to be read, typically zero bytes. ConnectionPool.get_connection has been modified to ensure that connections it returns are connected and are ready for a command to be sent. If get_connection encounters a case where a socket isn't ready for a command the connection is reconnected and checked again. TODO: more tests for this stuff. implement EPoll and KQueue selectors. Fixes #1115 Fixes #486
* Merge pull request #1129 from Chronial/feature/fix-exceptAndy McCurdy2019-02-011-4/+4
|\ | | | | Do not leave connections in invalid state