5

I want to perform the following scenario on redis using python.

Using command line: 1) redis-cli -c 2) redis_prompt >> get some_string

I tried using redis and rediscluster modules, but with no luck. Below are the codes that i tried:

1)

r = redis.Redis(host='123.123.123.123', port=6379, db=0)
r.get('some srting')

Got the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\redis\client.py", line 880, in get
    return self.execute_command('GET', name)
  File "C:\Python27\lib\site-packages\redis\client.py", line 573, in execute_command
    return self.parse_response(connection, command_name, **options)
  File "C:\Python27\lib\site-packages\redis\client.py", line 585, in parse_response
    response = connection.read_response()
  File "C:\Python27\lib\site-packages\redis\connection.py", line 582, in read_response
    raise response
redis.exceptions.ResponseError: MOVED 9442 172.16.176.36:6380

2)

from rediscluster import StrictRedisCluster
startup_nodes = [{"host": "123.123.123.123", "port": "7000"}]
rc_readonly = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True, readonly_mode=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\rediscluster\client.py", line 181, in __init__
    **kwargs
  File "C:\Python27\lib\site-packages\rediscluster\connection.py", line 353, in __init__
    **connection_kwargs)
  File "C:\Python27\lib\site-packages\rediscluster\connection.py", line 141, in __init__
    self.nodes.initialize()
  File "C:\Python27\lib\site-packages\rediscluster\nodemanager.py", line 240, in initialize
    raise RedisClusterException("Redis Cluster cannot be connected. Please provide at least one reachable node.")
rediscluster.exceptions.RedisClusterException: Redis Cluster cannot be connected. Please provide at least one reachable node.

Any help would be great.

3
  • The port is 6379 (in section 1) ? or 7000 (in section 2) Commented Jun 12, 2017 at 10:15
  • @Jacky i tried with both ports 6379 and 7000 for both section 1 and 2. Commented Jun 12, 2017 at 10:17
  • 1
    you need to contact to the redis administrator to make sure which port to use. And I want to know what exception raised if setting port to 6379 in section 2. Note that setting port to a number instead of string. Commented Jun 12, 2017 at 10:24

1 Answer 1

3

Ok, so this error means one of the following:

  • In these lines of code (1):

    r = redis.Redis(host='123.123.123.123', port=6379, db=0)
    
    r.get('some srting')
    

    you try to fetch the key "some sting" from host 123.123.123.123 and port 6379. The error redis.exceptions.ResponseError: MOVED 9442 172.16.176.36:6380 means that this key lies in 172.16.176.36:6380. So try to connect with ./redis-cli -c -p 6380 in this node and then execute CLUSTER GETKEYSINSLOT 6380 3 to see if this key is actually here.

  • From (2) this error: rediscluster.exceptions.RedisClusterException: Redis Cluster cannot be connected. Please provide at least one reachable node means that something is wrong with the cluster. Maybe, you have not made correct the initialization.

    First in /home/{{user}}/redis-yourversion/utils/create-cluster you will find create-cluster.sh. Set up port and host and nodes and then execute ./create-cluster start ./create-cluster-create. But first you have to start redis server in cluster mode. Go to redis.conf and in the configuration parameters you will see cluster-enabled no. Set up to yes. After this you must run ./redis-server ../redis.conf (give the path for redis.conf). If cluster enabled is correct you will see Running in cluster mode

Important thing to remember:

The parameter -c in terminal means that redis nodes can execute the redirections and find the correct node that the key belongs without MOVED errors. If you have a driver suppose in python to manipulate the nodes and fetch keys or whatever you must manage these redirections by yourself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.