hjr265.me / blog /

Passing A Vector of RedisModuleString to RedisModule_Call

November 26, 2022 #100DaysToOffload #Module #Redis

While building Redis Too (a recommendation engine module for Redis), I spent a good bit of time (and strands of hair) figuring out how to pass a variable number of arguments to a Redis command like “SUNION”.

The format specified of the RedisModule_Call function accepts ‘v’ to denote “a vector of RedisModuleString”. But to use it, you need to pass two arguments to RedisModule_Call: the array of RedisModuleString and the size of the array.

Assuming you have the array args defined as RedisModuleString **args, and the size of the array n as size_t n, you can call RedisModule_Call as follows:

RedisModule_Call(ctx, "SUNION", "v", args, n);

You can also mix it with other arguments in the call:

RedisModule_Call(ctx, "SUNIONSTORE", "sv", key, args, n); // `key` is a RedisModuleString.

This post is 1st of my #100DaysToOffload challenge. Want to get involved? Find out more at 100daystooffload.com.

comments powered by Disqus