Skip to content

Commit 7e3d779

Browse files
committed
get redis host/port from connection_pool object instead of main object
redis-py 2.4.0 removed host/port accessors on the main Redis object. If those accessors aren't available, get a connection object from the connection_pool and get the host/port from there. Store the host and port on the ResQ object so we don't have to keep poking the connection pool.
1 parent fe9aa2a commit 7e3d779

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pyres/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,17 @@ def _set_redis(self, server):
141141
self.dsn = server
142142
host, port = server.split(':')
143143
self._redis = Redis(host=host, port=int(port))
144+
self.host = host
145+
self.port = int(port)
144146
elif isinstance(server, Redis):
145-
self.dsn = '%s:%s' % (server.host,server.port)
147+
if hasattr(server, "host"):
148+
self.host = server.host
149+
self.port = server.port
150+
else:
151+
connection = server.connection_pool.get_connection()
152+
self.host = connection.host
153+
self.port = connection.port
154+
self.dsn = '%s:%s' % (self.host, self.port)
146155
self._redis = server
147156
else:
148157
raise Exception("I don't know what to do with %s" % str(server))
@@ -194,7 +203,7 @@ def info(self):
194203
'workers' : len(self.workers()),
195204
#'working' : len(self.working()),
196205
'failed' : Stat('failed',self).get(),
197-
'servers' : ['%s:%s' % (self.redis.host, self.redis.port)]
206+
'servers' : ['%s:%s' % (self.host, self.port)]
198207
}
199208

200209
def keys(self):

resweb/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def close(self):
2020
self.resq.close()
2121

2222
def address(self):
23-
return '%s:%s' % (self.resq.redis.host,self.resq.redis.port)
23+
return '%s:%s' % (self.resq.host,self.resq.port)
2424

2525
def version(self):
2626
return str(__version__)
@@ -263,7 +263,7 @@ def title(self):
263263
if self.key_id == 'resque':
264264
return 'Pyres'
265265
elif self.key_id == 'redis':
266-
return '%s:%s' % (self.resq.redis.host,self.resq.redis.port)
266+
return '%s:%s' % (self.resq.host,self.resq.port)
267267
elif self.key_id == 'keys':
268268
return 'Keys owned by Pyres'
269269
else:

0 commit comments

Comments
 (0)