Make error callback argument const
parent
ba42ab2ef8
commit
206868de06
|
@ -3,7 +3,7 @@
|
|||
#include <hiredis.h>
|
||||
|
||||
/* Prototype for the error callback. */
|
||||
typedef void (redisErrorCallback)(redisContext*);
|
||||
typedef void (redisErrorCallback)(const redisContext*);
|
||||
|
||||
/* This struct enables us to pass both the events and the
|
||||
* redisContext to the read and write handlers. */
|
||||
|
@ -73,11 +73,12 @@ void redisLibEventOnFree(redisContext *c, void *privdata) {
|
|||
free(e);
|
||||
}
|
||||
|
||||
redisContext *redisLibEventConnect(const char *ip, int port, redisErrorCallback *err, struct event_base *base) {
|
||||
redisContext *redisLibEventConnect(struct event_base *base, redisErrorCallback *err, const char *ip, int port) {
|
||||
redisEvents *e;
|
||||
redisContext *c = redisConnectNonBlock(ip, port, NULL);
|
||||
if (c->error != NULL) {
|
||||
err(c);
|
||||
redisFree(c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,18 +11,15 @@ void getCallback(redisContext *c, redisReply *reply, const void *privdata) {
|
|||
redisDisconnect(c);
|
||||
}
|
||||
|
||||
void errorCallback(redisContext *c) {
|
||||
void errorCallback(const redisContext *c) {
|
||||
printf("Error: %s\n", c->error);
|
||||
|
||||
/* Clean up the context when there was an error */
|
||||
redisFree(c);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
struct event_base *base = event_base_new();
|
||||
|
||||
redisContext *c = redisLibEventConnect("127.0.0.1", 6379, errorCallback, base);
|
||||
redisContext *c = redisLibEventConnect(base, errorCallback, "127.0.0.1", 6379);
|
||||
if (c == NULL) return 1;
|
||||
|
||||
redisCommand(c, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
|
||||
|
|
Loading…
Reference in New Issue