From cad13223f09d3c2541bdb6987ebdfa01b7edc33e Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 16 Jun 2014 14:22:55 +0200 Subject: [PATCH] Assign an unique non-repeating ID to each new client. This will be used by CLIENT KILL and is also a good way to ensure a given client is still the same across CLIENT LIST calls. The output of CLIENT LIST was modified to include the new ID, but this change is considered to be backward compatible as the API does not imply you can do positional parsing, since each filed as a different name. --- src/networking.c | 4 +++- src/redis.c | 1 + src/redis.h | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/networking.c b/src/networking.c index 960fd460..736ca5cb 100644 --- a/src/networking.c +++ b/src/networking.c @@ -72,6 +72,7 @@ redisClient *createClient(int fd) { } selectDb(c,0); + c->id = server.next_client_id++; c->fd = fd; c->name = NULL; c->bufpos = 0; @@ -1275,7 +1276,8 @@ sds catClientInfoString(sds s, redisClient *client) { if (emask & AE_WRITABLE) *p++ = 'w'; *p = '\0'; return sdscatfmt(s, - "addr=%s fd=%i name=%s age=%I idle=%I flags=%s db=%i sub=%i psub=%i multi=%i qbuf=%U qbuf-free=%U obl=%U oll=%U omem=%U events=%s cmd=%s", + "id=%U addr=%s fd=%i name=%s age=%I idle=%I flags=%s db=%i sub=%i psub=%i multi=%i qbuf=%U qbuf-free=%U obl=%U oll=%U omem=%U events=%s cmd=%s", + (unsigned long long) client->id, getClientPeerId(client), client->fd, client->name ? (char*)client->name->ptr : "", diff --git a/src/redis.c b/src/redis.c index 9558938b..1183f7bf 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1366,6 +1366,7 @@ void initServerConfig() { server.lua_time_limit = REDIS_LUA_TIME_LIMIT; server.lua_client = NULL; server.lua_timedout = 0; + server.next_client_id = 1; /* Client IDs, start from 1 .*/ server.loading_process_events_interval_bytes = (1024*1024*2); updateLRUClock(); diff --git a/src/redis.h b/src/redis.h index 5db01ac8..4c9cf117 100644 --- a/src/redis.h +++ b/src/redis.h @@ -451,6 +451,7 @@ typedef struct readyList { /* With multiplexing we need to take per-client state. * Clients are taken in a liked list. */ typedef struct redisClient { + uint64_t id; /* Client incremental unique ID. */ int fd; redisDb *db; int dictid; @@ -602,7 +603,8 @@ struct redisServer { list *clients_to_close; /* Clients to close asynchronously */ list *slaves, *monitors; /* List of slaves and MONITORs */ redisClient *current_client; /* Current client, only used on crash report */ - char neterr[ANET_ERR_LEN]; /* Error buffer for anet.c */ + char neterr[ANET_ERR_LEN]; /* Error buffer for anet.c */ + uint64_t next_client_id; /* Next client unique ID. Incremental. */ /* RDB / AOF loading information */ int loading; /* We are loading data from disk if true */ off_t loading_total_bytes;