From d5bde117c2f5477b5d0ba9846f2a7c4480ca1854 Mon Sep 17 00:00:00 2001 From: lowercase00 <21188280+lowercase00@users.noreply.github.com> Date: Tue, 7 Mar 2023 00:54:47 -0300 Subject: Remove `use_connection` (#1859) * feat: remove use_connection * fix: clear old test --- rq/__init__.py | 2 +- rq/connections.py | 20 ++------------------ 2 files changed, 3 insertions(+), 19 deletions(-) (limited to 'rq') diff --git a/rq/__init__.py b/rq/__init__.py index d5db681..ec635d7 100644 --- a/rq/__init__.py +++ b/rq/__init__.py @@ -1,6 +1,6 @@ # flake8: noqa -from .connections import Connection, get_current_connection, pop_connection, push_connection, use_connection +from .connections import Connection, get_current_connection, pop_connection, push_connection from .job import cancel_job, get_current_job, requeue_job, Retry from .queue import Queue from .version import VERSION diff --git a/rq/connections.py b/rq/connections.py index 413ee5a..2c6d227 100644 --- a/rq/connections.py +++ b/rq/connections.py @@ -3,7 +3,7 @@ from typing import Optional import warnings from redis import Redis -from .local import LocalStack, release_local +from .local import LocalStack class NoRedisConnectionException(Exception): @@ -65,22 +65,6 @@ def pop_connection() -> 'Redis': 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 @@ -118,4 +102,4 @@ 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'] -- cgit v1.2.1