projecteru / redis-trib.py

Redis Cluster lib in Python
MIT License
135 stars 45 forks source link

when I try to start a single cluster node, it failed with hiredis error #2

Closed GitProBo closed 8 years ago

GitProBo commented 8 years ago

redis-info ........

Cluster

cluster_enabled:1

Keyspace

10.1.100.219:7018> cluster info cluster_state:fail cluster_slots_assigned:0 cluster_slots_ok:0 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:1 cluster_size:0 cluster_current_epoch:0 cluster_my_epoch:0 cluster_stats_messages_sent:0 cluster_stats_messages_received:0

$ redis-trib.py start 10.1.100.219:7018 Redis-trib 0.4.1 Copyright (c) HunanTV Platform developers Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/bin/redis-trib.py", line 11, in sys.exit(main()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/redistrib/console.py", line 81, in main getattr(sys.modules[name], sys.argv[1])(_sys.argv[2:]) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/redistrib/console.py", line 14, in start command.start_cluster(__parse_host_port(host_port)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/redistrib/command.py", line 87, in start_cluster _add_slots(t, 0, SLOT_COUNT, max_slots) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/redistrib/command.py", line 81, in _add_slots addslots(t, begin, end) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/redistrib/command.py", line 71, in addslots m = t.talk('cluster', 'addslots', _xrange(begin, end)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/redistrib/clusternode.py", line 99, in talk return self.talk_raw(pack_command(_args)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/redistrib/clusternode.py", line 95, in talk_raw raise r hiredis.ReplyError: ERR Protocol error: expected '$', got '8'

zheplusplus commented 8 years ago

Thank you for the issue.

It seems the socket has truncated the command due to an unknown reason so that Redis received an ill-formarted command, and we indeed have the same experience, too. The patch is here.

One more parameter has been added to the API start_cluster to limit the number of slots in a single "cluster addslots" command. In fact we didn't convince the suspicious network problem but it works.

But unfortunately the fix doesn't affect the CLI command, as we plan to split the API from this project later, and add the click lib to enhance the option parsing. So we're not going to close this issue until this option is added to the CLI command.

To bypass this problem, you could try start_mutli from 2 Redis nodes and then let one of them quit.

zheplusplus commented 8 years ago

Redis-trib.py 0.5.0 was just released. You could now add the --max-slots option to specify the number of slots in one "cluster addslots" command (and it is by default 1024, not 16384 anymore, therefore you probably don't have to specify it).

The CLI approach in v0.5 changed to

redis-trib.py create HOST:PORT

in accordance with the ruby redis-trib tool. More details about the usage are at the wiki page.

Hope this would solve the problem.