Nordix / hiredis-cluster

C client library for Valkey/Redis Cluster. This project is used and sponsored by Ericsson. It is a fork of the now unmaintained hiredis-vip.
BSD 3-Clause "New" or "Revised" License
86 stars 42 forks source link

Unable to execute commands without keys (FLUSHALL, PING, INFO) #198

Closed arnaud-soulard closed 8 months ago

arnaud-soulard commented 8 months ago

I am currently using the library, especially the function redisClusterCommand(). I works fine when using commands with keys, for instance: "SET" "foo" "bar"

But, when I try to send a command without keys: FLUSHALL

I get the following error message: Error: No keys in command(must have keys for redis cluster mode)

This message comes from your library (in hircluster.c, command_format_by_slot function). As I am able to execute a "FLUSHALL" in a cluster when connected through redis-cli, I guess we should be able to do the same using your library.

I encounted the same issue using commands such as: PING, INFO

Did I miss something, do you see a workaround for me? Thanks

zuiderkwast commented 8 months ago

hiredis-cluster needs to know to which node to send the command. Normally it uses the key in a command to choose the node. For FLUSHALL I guess you want to send it to all nodes? Or just one?

You can use the node iterator to get each node. Then you can use redisClusterCommandToNode to send the command to each node. See https://github.com/Nordix/hiredis-cluster#cluster-node-iterator. You can also use redisClusterGetNodeByKey to get a node responsible for some key.

arnaud-soulard commented 8 months ago

Okay, you're right, thank you very much for your response. My intention was to send the flushall command to all nodes.