0

I have tried using this from both python 3.6 and 3.9 but get the same error:

pip install serialized-redis-interface
Collecting serialized-redis-interface
  Using cached serialized_redis_interface-0.3.1-py3-none-any.whl (7.8 kB)
Requirement already satisfied: redis>3 in /home/idf/anaconda3/envs/works/lib/python3.6/site-packages (from serialized-redis-interface) (4.3.5)
Requirement already satisfied: packaging>=20.4 in /home/idf/anaconda3/envs/works/lib/python3.6/site-packages (from redis>3->serialized-redis-interface) (21.3)
Requirement already satisfied: typing-extensions in /home/idf/anaconda3/envs/works/lib/python3.6/site-packages (from redis>3->serialized-redis-interface) (4.1.1)
Requirement already satisfied: importlib-metadata>=1.0 in /home/idf/anaconda3/envs/works/lib/python3.6/site-packages (from redis>3->serialized-redis-interface) (4.8.3)
Requirement already satisfied: async-timeout>=4.0.2 in /home/idf/anaconda3/envs/works/lib/python3.6/site-packages (from redis>3->serialized-redis-interface) (4.0.2)
Requirement already satisfied: zipp>=0.5 in /home/idf/anaconda3/envs/works/lib/python3.6/site-packages (from importlib-metadata>=1.0->redis>3->serialized-redis-interface) (3.6.0)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /home/idf/anaconda3/envs/works/lib/python3.6/site-packages (from packaging>=20.4->redis>3->serialized-redis-interface) (3.0.9)
Installing collected packages: serialized-redis-interface
Successfully installed serialized-redis-interface-0.3.1

This code doesn't work (but it used to work, not sure what this new installation broke):

import serialized_redis

def connect_redis(redis_host, redis_port, redis_password):

    print("Connecting redis")

    try:

        # The decode_repsonses flag here directs the client to convert the responses from Redis into Python strings
        # using the default encoding utf-8.  This is client specific.
        redis_connection_object = serialized_redis.JSONSerializedRedis(host=redis_host, port=redis_port, password=redis_password, db=0)
        #redis.StrictRedis(host=redis_host, port=redis_port, password=redis_password, decode_responses=True)
        if None == redis_connection_object:
            print("redis is not connected")
        return redis_connection_object
    except Exception as e:
        print(e)

        return None

The error:

Traceback (most recent call last):
  File "options.py", line 42, in <module>
    from redis_connection import connect_redis
  File "/home/idf/Downloads/backup/amplify/redis_connection.py", line 1, in <module>
    import serialized_redis
  File "/home/idf/anaconda3/envs/works/lib/python3.6/site-packages/serialized_redis/__init__.py", line 5, in <module>
    from redis.client import string_keys_to_dict, dict_merge
ImportError: cannot import name 'dict_merge'
Ivan
  • 7,448
  • 14
  • 69
  • 134
  • 1
    I'm not an expert, so take this with a grain of salt, but I've seen similar issues before in other packages. It seems the method `dict_merge` was removed from `redis.client` in [this commit](https://github.com/redis/redis-py/commit/8c5a41baf0bd2a1388d601e5b49d06b91997ccb8). Your `serialized_redis_interface` doesn't seem to be aware of that, since it's still trying to import it. That change was first included in a release in the [4.0.0-beta1 version](https://github.com/redis/redis-py/releases/tag/v4.0.0b1). You might need to downgrade your `redis` package to something lower than version 4. – Savir Feb 04 '23 at 22:07
  • 1
    It's a pesky but common behavior. The release dates match: In [February 2019](https://pypi.org/project/serialized-redis-interface/#history) the folks who coded the serialized_redis_interface said _"This needs redis version > 3 to work"_ But then the redis guys released version 4 in 2021, with breaking changes. The serialized_redis_interface was never updated (its latest version was released on Feb. 2019) and since `redis 4` IS `> 3`, the `serialized_redis_interface` package is "happy" (when it shouldn't be). – Savir Feb 04 '23 at 22:13

0 Answers0