Skip to content

Commit b07f6d6

Browse files
committed
Merge pull request binarymatt#118 from adammeghji/master
Add support for Redis db num in server string: i.e. localhost:6379/0
2 parents d54343e + 2e48ebd commit b07f6d6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pyres/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class ResQ(object):
113113
114114
The ``__init__`` takes these keyword arguments:
115115
116-
``server`` -- IP address and port of the Redis server to which you want to connect. Default is `localhost:6379`.
116+
``server`` -- IP address and port of the Redis server to which you want to connect, and optional Redis DB number. Default is `localhost:6379`.
117117
118118
``password`` -- The password, if required, of your Redis server. Default is "None".
119119
@@ -185,8 +185,9 @@ def _get_redis(self):
185185
def _set_redis(self, server):
186186
if isinstance(server, basestring):
187187
self.dsn = server
188-
host, port = server.split(':')
189-
self._redis = Redis(host=host, port=int(port), password=self.password)
188+
address, _, db = server.partition('/')
189+
host, port = address.split(':')
190+
self._redis = Redis(host=host, port=int(port), db=int(db or 0), password=self.password)
190191
self.host = host
191192
self.port = int(port)
192193
elif isinstance(server, Redis):

pyres/worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Worker(object):
1919
class and passes a comma-separated list of queues to listen on.::
2020
2121
>>> from pyres.worker import Worker
22-
>>> Worker.run([queue1, queue2], server="localhost:6379")
22+
>>> Worker.run([queue1, queue2], server="localhost:6379/0")
2323
2424
"""
2525

0 commit comments

Comments
 (0)