summaryrefslogtreecommitdiff
path: root/rq/connections.py
diff options
context:
space:
mode:
Diffstat (limited to 'rq/connections.py')
-rw-r--r--rq/connections.py48
1 files changed, 26 insertions, 22 deletions
diff --git a/rq/connections.py b/rq/connections.py
index 413ee5a..0d39e43 100644
--- a/rq/connections.py
+++ b/rq/connections.py
@@ -1,9 +1,10 @@
+import warnings
from contextlib import contextmanager
from typing import Optional
-import warnings
+
from redis import Redis
-from .local import LocalStack, release_local
+from .local import LocalStack
class NoRedisConnectionException(Exception):
@@ -31,7 +32,8 @@ def Connection(connection: Optional['Redis'] = None): # noqa
connection (Optional[Redis], optional): A Redis Connection instance. Defaults to None.
"""
warnings.warn(
- "The Conneciton context manager is deprecated. Use the `connection` parameter instead.", DeprecationWarning
+ "The Connection context manager is deprecated. Use the `connection` parameter instead.",
+ DeprecationWarning,
)
if connection is None:
connection = Redis()
@@ -41,7 +43,8 @@ def Connection(connection: Optional['Redis'] = None): # noqa
finally:
popped = pop_connection()
assert popped == connection, (
- 'Unexpected Redis connection was popped off the stack. ' 'Check your Redis connection setup.'
+ 'Unexpected Redis connection was popped off the stack. '
+ 'Check your Redis connection setup.'
)
@@ -52,6 +55,10 @@ def push_connection(redis: 'Redis'):
Args:
redis (Redis): A Redis connection
"""
+ warnings.warn(
+ "The `push_connection` function is deprecated. Pass the `connection` explicitly instead.",
+ DeprecationWarning,
+ )
_connection_stack.push(redis)
@@ -62,25 +69,13 @@ def pop_connection() -> 'Redis':
Returns:
redis (Redis): A Redis connection
"""
+ warnings.warn(
+ "The `pop_connection` function is deprecated. Pass the `connection` explicitly instead.",
+ DeprecationWarning,
+ )
return _connection_stack.pop()
-def use_connection(redis: Optional['Redis'] = None):
- """
- Clears the stack and uses the given connection. Protects against mixed
- use of use_connection() and stacked connection contexts.
-
- Args:
- redis (Optional[Redis], optional): A Redis Connection. Defaults to None.
- """
- assert len(_connection_stack) <= 1, 'You should not mix Connection contexts with use_connection()'
- release_local(_connection_stack)
-
- if redis is None:
- redis = Redis()
- push_connection(redis)
-
-
def get_current_connection() -> 'Redis':
"""
Returns the current Redis connection (i.e. the topmost on the
@@ -89,6 +84,10 @@ def get_current_connection() -> 'Redis':
Returns:
Redis: A Redis Connection
"""
+ warnings.warn(
+ "The `get_current_connection` function is deprecated. Pass the `connection` explicitly instead.",
+ DeprecationWarning,
+ )
return _connection_stack.top
@@ -106,7 +105,10 @@ def resolve_connection(connection: Optional['Redis'] = None) -> 'Redis':
Returns:
Redis: A Redis Connection
"""
-
+ warnings.warn(
+ "The `resolve_connection` function is deprecated. Pass the `connection` explicitly instead.",
+ DeprecationWarning,
+ )
if connection is not None:
return connection
@@ -118,4 +120,6 @@ def resolve_connection(connection: Optional['Redis'] = None) -> 'Redis':
_connection_stack = LocalStack()
-__all__ = ['Connection', 'get_current_connection', 'push_connection', 'pop_connection', 'use_connection']
+
+__all__ = ['Connection', 'get_current_connection', 'push_connection', 'pop_connection']
+