'How to store dictionary in redis from python

I'm trying to store a python dict in memory through redis, I was following the pypi doc, when I try to instance RedisCluster i got this error:

from redis.cluster import RedisCluster as Redis # this line works
rc = Redis(host='localhost', port=6379) # here is the problem
Traceback (most recent call last):
  File "/home/developer/.pyenv/versions/redisTesting/lib/python3.9/site-packages/redis/cluster.py", line 1306, in initialize
    raise RedisClusterException(
redis.exceptions.RedisClusterException: Cluster mode is not enabled on this node
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/developer/.pyenv/versions/3.9.5/lib/python3.9/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "/home/developer/.pyenv/versions/redisTesting/lib/python3.9/site-packages/redis/cluster.py", line 507, in __init__
    self.nodes_manager = NodesManager(
  File "/home/developer/.pyenv/versions/redisTesting/lib/python3.9/site-packages/redis/cluster.py", line 1128, in __init__
    self.initialize()
  File "/home/developer/.pyenv/versions/redisTesting/lib/python3.9/site-packages/redis/cluster.py", line 1334, in initialize
    raise RedisClusterException(
redis.exceptions.RedisClusterException: ERROR sending "cluster slots" command to redis server 127.0.0.1:6379. error: Cluster mode is not enabled on this node

I know that the problem is Cluster mode is not enabled on this node but I didn't find a way to solve this error, how can enable the cluster mode on the node?

Also I find a way to store this dict in memory with

import redis

r = redis.Redis()
r.hmset({
    "color": "green",
    "price": 99.99,
    "style": "baseball",
    "quantity": 200,
    "npurchased": 0,
})

but this got me a deprecate warning <input>:1: DeprecationWarning: Redis.hmset() is deprecated. Use Redis.hset() instead. and when I tryed to use r.hset() the terminal got me redis.exceptions.DataError: Invalid input of type: 'dict'. Convert to a bytes, string, int or float first.



Solution 1:[1]

Change redis.cluster to redis and connection would succeed.

#from redis.cluster import RedisCluster as Redis # this line works (but assumes you are connecting to Redis Cluster)
from redis import Redis
rc = Redis(host='localhost', port=6379) 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anton