From 297af190d8eae782825dce987cb5eb9b4f0842fe Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 26 May 2011 16:56:09 +0000 Subject: [PATCH] clean up orphaned redis keys --- daemon/redis.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/daemon/redis.c b/daemon/redis.c index a1b4ba23f..c7f62b67d 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -268,6 +268,7 @@ void redis_update(struct call *c) { struct callstream *cs; int i, count = 0; struct peer *p; + redisReply *oldstreams; if (!r) return; @@ -276,6 +277,7 @@ void redis_update(struct call *c) { uuid_str_generate(c->redis_uuid); redis_check_type(r, c->redis_uuid, NULL, "hash"); + oldstreams = redisCommand(r->ctx, "LRANGE %s-streams 0 -1", c->redis_uuid); redisAppendCommand(r->ctx, "HMSET %s callid %s created %i", c->redis_uuid, c->callid, c->created); redisAppendCommand(r->ctx, "DEL %s-streams-temp", c->redis_uuid); @@ -298,12 +300,24 @@ void redis_update(struct call *c) { count++; } - redisAppendCommand(r->ctx, "RENAME %s-streams-temp %s-streams", c->redis_uuid, c->redis_uuid); /* XXX causes orphaned keys */ + redisAppendCommand(r->ctx, "RENAME %s-streams-temp %s-streams", c->redis_uuid, c->redis_uuid); redisAppendCommand(r->ctx, "EXPIRE %s-streams 86400", c->redis_uuid); redisAppendCommand(r->ctx, "EXPIRE %s 86400", c->redis_uuid); redisAppendCommand(r->ctx, "SADD calls %s", c->redis_uuid); count += 4; + if (oldstreams) { + if (oldstreams->type == REDIS_REPLY_ARRAY) { + for (i = 0; i < oldstreams->elements; i++) { + if (oldstreams->element[0]->type == REDIS_REPLY_STRING) { + redisAppendCommand(r->ctx, "DEL %s:0 %s:1", oldstreams->element[0]->str, oldstreams->element[0]->str); + count++; + } + } + } + freeReplyObject(oldstreams); + } + redis_consume(r, count); }