summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBo Bayles <bbayles@gmail.com>2020-05-15 19:35:08 -0500
committerGitHub <noreply@github.com>2020-05-16 07:35:08 +0700
commit5859339a51e5f5d902d1d07603f41d95008e1065 (patch)
tree74b522e0cce54e734bc79d45d4d847eaffe1aeda
parente6e5703f28811d2136b88462664c54f747179549 (diff)
downloadrq-5859339a51e5f5d902d1d07603f41d95008e1065.tar.gz
Avoid deprecation warnings on redis-py 3.5.0 hmset (#1253)
-rw-r--r--rq/compat/__init__.py11
-rw-r--r--rq/job.py5
-rw-r--r--rq/worker.py4
3 files changed, 15 insertions, 5 deletions
diff --git a/rq/compat/__init__.py b/rq/compat/__init__.py
index 3f8b3aa..d62c89c 100644
--- a/rq/compat/__init__.py
+++ b/rq/compat/__init__.py
@@ -103,4 +103,13 @@ except ImportError:
def dst(self, dt):
return timedelta(0)
- utc = UTC() \ No newline at end of file
+ utc = UTC()
+
+
+def hmset(pipe_or_connection, name, mapping):
+ # redis-py versions 3.5.0 and above accept a mapping parameter for hset
+ try:
+ return pipe_or_connection.hset(name, mapping=mapping)
+ # earlier versions require hmset to be used
+ except TypeError:
+ return pipe_or_connection.hmset(name, mapping)
diff --git a/rq/job.py b/rq/job.py
index 15e706b..2c1251d 100644
--- a/rq/job.py
+++ b/rq/job.py
@@ -7,7 +7,8 @@ import warnings
import zlib
from uuid import uuid4
-from rq.compat import as_text, decode_redis_hash, string_types, text_type
+from rq.compat import (as_text, decode_redis_hash, hmset, string_types,
+ text_type)
from .connections import resolve_connection
from .exceptions import NoSuchJobError
@@ -547,7 +548,7 @@ class Job(object):
key = self.key
connection = pipeline if pipeline is not None else self.connection
- connection.hmset(key, self.to_dict(include_meta=include_meta))
+ hmset(connection, key, self.to_dict(include_meta=include_meta))
def save_meta(self):
"""Stores job meta from the job instance to the corresponding Redis key."""
diff --git a/rq/worker.py b/rq/worker.py
index 2ebfcec..91ffc23 100644
--- a/rq/worker.py
+++ b/rq/worker.py
@@ -23,7 +23,7 @@ except ImportError:
from redis import WatchError
from . import worker_registration
-from .compat import PY2, as_text, string_types, text_type
+from .compat import PY2, as_text, hmset, string_types, text_type
from .connections import get_current_connection, push_connection, pop_connection
from .defaults import (DEFAULT_RESULT_TTL,
@@ -268,7 +268,7 @@ class Worker(object):
now = utcnow()
now_in_string = utcformat(now)
self.birth_date = now
- p.hmset(key, {
+ hmset(p, key, mapping={
'birth': now_in_string,
'last_heartbeat': now_in_string,
'queues': queues,