The function definition provided in the source for redisAsyncCommand( ) is:
static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *cmd, size_t len) { ... }
What is the purpose of the void *privdata
argument? In what cases would it be useful?
As I understand by reading the code on gihub, the purpose of privdata is to send your callback some predefined data (which can be anything; that is why void* is used). In your callback (fn pointer to redisCallbackFn) you will recieve that privdata as parameter (for example look at
cb->fn(ac,reply,cb->privdata);
in func__redisRunCallback
fileasync.c
)For example (simplified pseudo code for something similar) is bellow. In this example there are 3 successive calls to __redisAsyncCommandSimplified and only one handler (callback). In callback I have used privdata to determine behavior of callback. Your callback can also use that privdata data for something else (like parameter for another function call, logging, structure creation/population, etc)...