Fix for restoring notified call from own redis db

pull/225/head
Frederic-Philippe Metz 10 years ago
parent 48543b4c4e
commit bf38f151ba

@ -427,6 +427,7 @@ struct callmaster_config {
struct redis *redis;
struct redis *redis_read;
struct redis *redis_write;
struct redis *redis_read_notify;
struct event_base *redis_notify_event_base;
struct redisAsyncContext *redis_notify_async_context;
char *b2b_url;

@ -559,19 +559,19 @@ no_kernel:
}
if (!is_addr_unspecified(&redis_ep.address)) {
mc.redis = redis_new(&redis_ep, redis_db, MASTER_REDIS_ROLE);
mc.redis = mc.redis_read_notify = redis_new(&redis_ep, redis_db, MASTER_REDIS_ROLE);
if (!mc.redis)
die("Cannot start up without Redis database");
}
if (!is_addr_unspecified(&redis_read_ep.address)) {
mc.redis_read = redis_new(&redis_read_ep, redis_read_db, ANY_REDIS_ROLE);
mc.redis_read = mc.redis_read_notify = redis_new(&redis_read_ep, redis_read_db, ANY_REDIS_ROLE);
if (!mc.redis_read)
die("Cannot start up without Redis read database");
}
if (!is_addr_unspecified(&redis_write_ep.address)) {
mc.redis_write = redis_new(&redis_write_ep, redis_write_db, ANY_REDIS_ROLE);
mc.redis_write = mc.redis_read_notify = redis_new(&redis_write_ep, redis_write_db, ANY_REDIS_ROLE);
if (!mc.redis_write)
die("Cannot start up without Redis write database");
}

@ -226,15 +226,22 @@ void onRedisNotification(redisAsyncContext *actx, void *reply, void *privdata) {
unsigned char* p = 0;
int dbno;
if (cm->conf.redis_read) {
r = cm->conf.redis_read;
} else if (cm->conf.redis) {
r = cm->conf.redis;
} else {
if (!(cm->conf.redis_read) && !(cm->conf.redis)) {
rlog(LOG_ERROR, "A redis notification has been there but role was not 'master' or 'read'");
return;
}
r = cm->conf.redis_read_notify;
// if (cm->conf.redis_read) {
// r = cm->conf.redis_read_notify;
// } else if (cm->conf.redis) {
// r = cm->conf.redis_read_notify;
// } else {
// rlog(LOG_ERROR, "A redis notification has been there but role was not 'master' or 'read'");
// return;
// }
redisReply *rr = (redisReply*)reply;
if (reply == NULL || rr->type != REDIS_REPLY_ARRAY)
@ -265,7 +272,16 @@ void onRedisNotification(redisAsyncContext *actx, void *reply, void *privdata) {
return;
}
}
dbno = atoi(db_str);
dbno = r->db = atoi(db_str);
// select the right db for restoring the call
if (redisCommandNR(r->ctx, "SELECT %i", r->db)) {
if (r->ctx->err)
rlog(LOG_ERR, "Redis error: %s", r->ctx->errstr);
redisFree(r->ctx);
r->ctx = NULL;
return;
}
pch += strlen("notifier-");
str_cut(rr->element[2]->str,0,pch-rr->element[2]->str);
@ -302,14 +318,14 @@ void redis_notify_event_base_loopbreak(struct callmaster *cm) {
}
void redis_notify_subscribe_keyspace(struct callmaster *cm, int keyspace) {
char* main_db_str[256];
char* main_db_str[256]; memset(&main_db_str,0,256);
sprintf(main_db_str,"psubscribe __keyspace@%i*:notifier-*", keyspace);
redisAsyncCommand(cm->conf.redis_notify_async_context, onRedisNotification, (void*)cm, main_db_str);
}
void redis_notify_unsubscribe_keyspace(struct callmaster *cm, int keyspace) {
char* main_db_str[256];
char* main_db_str[256]; memset(&main_db_str,0,256);
sprintf(main_db_str,"punsubscribe __keyspace@%i*:notifier-*", keyspace);
redisAsyncCommand(cm->conf.redis_notify_async_context, onRedisNotification, (void*)cm, main_db_str);

Loading…
Cancel
Save