summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelwin Ong <selwin.ong@gmail.com>2020-05-23 19:57:11 +0700
committerSelwin Ong <selwin.ong@gmail.com>2020-05-23 19:57:11 +0700
commitfc9865b169e834fbb8d54eebafc0f906ca621736 (patch)
tree79b4ebadd84fe2c83f4a3017e3b3b9eaba610bdf
parent52e426f40ffee046f06269fc2e7593707230e9f6 (diff)
downloadrq-hmset.tar.gz
Attempt to fix hmset command for Redis < 4.0hmset
-rw-r--r--rq/compat/__init__.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/rq/compat/__init__.py b/rq/compat/__init__.py
index d62c89c..d87291a 100644
--- a/rq/compat/__init__.py
+++ b/rq/compat/__init__.py
@@ -4,6 +4,8 @@ from __future__ import (absolute_import, division, print_function,
import sys
+from redis.exceptions import ResponseError
+
def is_python_version(*versions):
for version in versions:
@@ -107,9 +109,14 @@ except ImportError:
def hmset(pipe_or_connection, name, mapping):
- # redis-py versions 3.5.0 and above accept a mapping parameter for hset
+ # redis-py versions 3.5.0 marks hmset as deprecated and introduces
+ # a "mapping" parameter for hset
try:
- return pipe_or_connection.hset(name, mapping=mapping)
+ try:
+ return pipe_or_connection.hset(name, mapping=mapping)
+ except ResponseError:
+ # On Redis server < 4.0, we have to fallback to hmset
+ return pipe_or_connection.hmset(name, mapping)
# earlier versions require hmset to be used
except TypeError:
return pipe_or_connection.hmset(name, mapping)