summaryrefslogtreecommitdiff
path: root/redis/sentinel.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-08-06 15:15:02 -0700
committerGitHub <noreply@github.com>2020-08-06 15:15:02 -0700
commit8c5a41baf0bd2a1388d601e5b49d06b91997ccb8 (patch)
tree89cad14d95927f8ea696706c2b1399dde17fa244 /redis/sentinel.py
parentc6f13c3b69d32257ab75ba9d824e5b555f91572c (diff)
downloadredis-py-8c5a41baf0bd2a1388d601e5b49d06b91997ccb8.tar.gz
Remove support for end-of-life Python 2.7 (#1318)
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>
Diffstat (limited to 'redis/sentinel.py')
-rw-r--r--redis/sentinel.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/redis/sentinel.py b/redis/sentinel.py
index 203c859..b9d77f1 100644
--- a/redis/sentinel.py
+++ b/redis/sentinel.py
@@ -5,7 +5,7 @@ from redis.client import Redis
from redis.connection import ConnectionPool, Connection
from redis.exceptions import (ConnectionError, ResponseError, ReadOnlyError,
TimeoutError)
-from redis._compat import iteritems, nativestr, xrange
+from redis.utils import str_if_bytes
class MasterNotFoundError(ConnectionError):
@@ -19,7 +19,7 @@ class SlaveNotFoundError(ConnectionError):
class SentinelManagedConnection(Connection):
def __init__(self, **kwargs):
self.connection_pool = kwargs.pop('connection_pool')
- super(SentinelManagedConnection, self).__init__(**kwargs)
+ super().__init__(**kwargs)
def __repr__(self):
pool = self.connection_pool
@@ -31,10 +31,10 @@ class SentinelManagedConnection(Connection):
def connect_to(self, address):
self.host, self.port = address
- super(SentinelManagedConnection, self).connect()
+ super().connect()
if self.connection_pool.check_connection:
self.send_command('PING')
- if nativestr(self.read_response()) != 'PONG':
+ if str_if_bytes(self.read_response()) != 'PONG':
raise ConnectionError('PING failed')
def connect(self):
@@ -52,7 +52,7 @@ class SentinelManagedConnection(Connection):
def read_response(self):
try:
- return super(SentinelManagedConnection, self).read_response()
+ return super().read_response()
except ReadOnlyError:
if self.connection_pool.is_master:
# When talking to a master, a ReadOnlyError when likely
@@ -78,7 +78,7 @@ class SentinelConnectionPool(ConnectionPool):
'connection_class', SentinelManagedConnection)
self.is_master = kwargs.pop('is_master', True)
self.check_connection = kwargs.pop('check_connection', False)
- super(SentinelConnectionPool, self).__init__(**kwargs)
+ super().__init__(**kwargs)
self.connection_kwargs['connection_pool'] = weakref.proxy(self)
self.service_name = service_name
self.sentinel_manager = sentinel_manager
@@ -91,7 +91,7 @@ class SentinelConnectionPool(ConnectionPool):
)
def reset(self):
- super(SentinelConnectionPool, self).reset()
+ super().reset()
self.master_address = None
self.slave_rr_counter = None
@@ -119,7 +119,7 @@ class SentinelConnectionPool(ConnectionPool):
if slaves:
if self.slave_rr_counter is None:
self.slave_rr_counter = random.randint(0, len(slaves) - 1)
- for _ in xrange(len(slaves)):
+ for _ in range(len(slaves)):
self.slave_rr_counter = (
self.slave_rr_counter + 1) % len(slaves)
slave = slaves[self.slave_rr_counter]
@@ -132,7 +132,7 @@ class SentinelConnectionPool(ConnectionPool):
raise SlaveNotFoundError('No slave found for %r' % (self.service_name))
-class Sentinel(object):
+class Sentinel:
"""
Redis Sentinel cluster client
@@ -168,7 +168,7 @@ class Sentinel(object):
if sentinel_kwargs is None:
sentinel_kwargs = {
k: v
- for k, v in iteritems(connection_kwargs)
+ for k, v in connection_kwargs.items()
if k.startswith('socket_')
}
self.sentinel_kwargs = sentinel_kwargs