[BUG] Sharding is using the wrong key on module commands
victor-timofei opened this issue ยท 3 comments
Describe the bug
We are trying to send a redis module command using the AsyncRedisCluster
interface.
We are using the generic command interface AsyncRedisCluster::command(Input first, Input last, Callback &&cb)
.
Our redis module command format looks like module-name subcommand <key> ...args
.
We discovered that the redis++ library uses the second argument as the key for the sharding.
In our case as it can be seen in the example command format, the key is the 3rd argument.
To Reproduce
This minimal code is without async and callbacks due to its simplicity, but the behavior is the same.
auto redis = RedisCluster("tcp://127.0.0.1:6379");
std::vector<std::string> raw_cmd;
raw_cmd.push_back("module-name");
raw_cmd.push_back("create");
raw_cmd.push_back("key2");
raw_cmd.push_back("arg1");
raw_cmd.push_back("arg2");
redis.command<void>(raw_cmd.begin(), raw_cmd.end());
Expected behavior
We would like to be able to use the command interface so as to be able to send to db commands like:
module-name create key1 arg1 arg2..
module-name delete key2 arg3 arg4 arg5..
And do the hashing based on the key.
Environment:
- OS: Rocky Linux 8.6
- Compiler: gcc (GCC) 8.5.0
- hiredis version: 1.2.0
- redis-plus-plus version: 1.3.10
Additional context
Add any other context about the problem here.
Yes, redis-plus-plus' generic interface uses the second command argument as key. In order to work around it, you can create an AsyncRedis object with AsyncRedisCluster, and send the command to it with this new AsyncRedis object:
auto r = async_redis_cluster.redis("key", false); // create it with a connection from the underlying connection pool
r.command<void>(raw_cmd.begin(), raw_cmd.end());
Regards
Hi @sewenew. Thanks a lot for the workaround. We validated this works.
I think it would be useful to have this workaround as a note on the docs under the Redis Modules section. I could help with adding that.
@victor-timofei You're always welcome to create a pull request to fix the doc. Thanks a lot!
Regards