summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandy <andy@whiskeymedia.com>2013-04-22 21:57:26 -0700
committerandy <andy@whiskeymedia.com>2013-04-22 21:57:26 -0700
commitc968d78bfb3a977ce3b14fab7196f19cec645bdf (patch)
tree23bcba305ba849ac60589b79f804a707b399022d
parentb16d00993d61aa53304342256f8280bdae6ca21b (diff)
downloadredis-py-c968d78bfb3a977ce3b14fab7196f19cec645bdf.tar.gz
pep8
-rw-r--r--redis/__init__.py2
-rw-r--r--redis/_compat.py8
-rw-r--r--redis/client.py1
-rw-r--r--redis/connection.py5
-rw-r--r--tests/connection_pool.py22
5 files changed, 18 insertions, 20 deletions
diff --git a/redis/__init__.py b/redis/__init__.py
index 5d9f3f1..065c4d4 100644
--- a/redis/__init__.py
+++ b/redis/__init__.py
@@ -22,7 +22,7 @@ __version__ = '2.7.2'
VERSION = tuple(map(int, __version__.split('.')))
__all__ = [
- 'Redis', 'StrictRedis', 'ConnectionPool',
+ 'Redis', 'StrictRedis', 'ConnectionPool', 'BlockingConnectionPool',
'Connection', 'UnixDomainSocketConnection',
'RedisError', 'ConnectionError', 'ResponseError', 'AuthenticationError',
'InvalidResponse', 'DataError', 'PubSubError', 'WatchError', 'from_url',
diff --git a/redis/_compat.py b/redis/_compat.py
index 4a8a14c..2f7cafa 100644
--- a/redis/_compat.py
+++ b/redis/_compat.py
@@ -49,16 +49,17 @@ else:
bytes = bytes
long = int
-try: # Python 3
+try: # Python 3
from queue import LifoQueue, Empty, Full
except ImportError:
from Queue import Empty, Full
- try: # Python 2.6 - 2.7
+ try: # Python 2.6 - 2.7
from Queue import LifoQueue
- except ImportError: # Python 2.5
+ except ImportError: # Python 2.5
from Queue import Queue
# From the Python 2.7 lib. Python 2.5 already extracted the core
# methods to aid implementating different queue organisations.
+
class LifoQueue(Queue):
"""Override queue methods to implement a last-in first-out queue."""
@@ -74,4 +75,3 @@ except ImportError:
def _get(self):
return self.queue.pop()
-
diff --git a/redis/client.py b/redis/client.py
index ea8b5cf..941fb1d 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -137,6 +137,7 @@ def sort_return_tuples(response, **options):
n = options['groups']
return list(izip(*[response[i::n] for i in range(n)]))
+
def int_or_none(response):
if response is None:
return None
diff --git a/redis/connection.py b/redis/connection.py
index ccfedf6..a1520a2 100644
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -476,7 +476,7 @@ class BlockingConnectionPool(object):
is_valid = isinstance(max_connections, int) and max_connections > 0
if not is_valid:
raise ValueError('``max_connections`` must be a positive integer')
-
+
# Get the current process id, so we can disconnect and reinstantiate if
# it changes.
self.pid = os.getpid()
@@ -539,7 +539,7 @@ class BlockingConnectionPool(object):
connection = self.pool.get(block=True, timeout=self.timeout)
except Empty:
# Note that this is not caught by the redis client and will be raised
- # unless handled by application code. If you want never to raise
+ # unless handled by application code. If you want never to raise
raise ConnectionError("No connection available.")
# If the ``connection`` is actually ``None`` then that's a cue to make a
@@ -579,4 +579,3 @@ class BlockingConnectionPool(object):
self.__init__(max_connections=self.max_connections, timeout=self.timeout,
connection_class=self.connection_class,
queue_class=self.queue_class, **self.connection_kwargs)
-
diff --git a/tests/connection_pool.py b/tests/connection_pool.py
index 91d4d46..673c2f7 100644
--- a/tests/connection_pool.py
+++ b/tests/connection_pool.py
@@ -32,14 +32,14 @@ class ConnectionPoolTestCase(unittest.TestCase):
def test_max_connections(self):
pool = self.get_pool(max_connections=2)
- c1 = pool.get_connection('_')
- c2 = pool.get_connection('_')
+ pool.get_connection('_')
+ pool.get_connection('_')
self.assertRaises(redis.ConnectionError, pool.get_connection, '_')
def test_blocking_max_connections(self):
pool = self.get_pool(max_connections=2)
- c1 = pool.get_connection('_')
- c2 = pool.get_connection('_')
+ pool.get_connection('_')
+ pool.get_connection('_')
self.assertRaises(redis.ConnectionError, pool.get_connection, '_')
def test_release(self):
@@ -74,11 +74,10 @@ class BlockingConnectionPoolTestCase(unittest.TestCase):
"""Getting a connection should block for until available."""
import time
- from copy import deepcopy
from threading import Thread
# We use a queue for cross thread communication within the unit test.
- try: # Python 3
+ try: # Python 3
from queue import Queue
except ImportError:
from Queue import Queue
@@ -87,8 +86,8 @@ class BlockingConnectionPoolTestCase(unittest.TestCase):
q.put_nowait('Not yet got')
pool = self.get_pool(max_connections=2, timeout=5)
c1 = pool.get_connection('_')
- c2 = pool.get_connection('_')
-
+ pool.get_connection('_')
+
target = lambda: q.put_nowait(pool.get_connection('_'))
Thread(target=target).start()
@@ -96,7 +95,7 @@ class BlockingConnectionPoolTestCase(unittest.TestCase):
time.sleep(0.05)
c3 = q.get_nowait()
self.assertEquals(c3, 'Not yet got')
-
+
# Then got when available.
pool.release(c1)
time.sleep(0.05)
@@ -107,8 +106,8 @@ class BlockingConnectionPoolTestCase(unittest.TestCase):
"""Getting a connection raises ``ConnectionError`` after timeout."""
pool = self.get_pool(max_connections=2, timeout=0.1)
- c1 = pool.get_connection('_')
- c2 = pool.get_connection('_')
+ pool.get_connection('_')
+ pool.get_connection('_')
self.assertRaises(redis.ConnectionError, pool.get_connection, '_')
def test_release(self):
@@ -117,4 +116,3 @@ class BlockingConnectionPoolTestCase(unittest.TestCase):
pool.release(c1)
c2 = pool.get_connection('_')
self.assertEquals(c1, c2)
-