Commit f26f79ea authored by antirez's avatar antirez
Browse files

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.
parent 56d26c23
...@@ -83,6 +83,7 @@ redisClient *createClient(int fd) { ...@@ -83,6 +83,7 @@ redisClient *createClient(int fd) {
} }
selectDb(c,0); selectDb(c,0);
c->id = server.next_client_id++;
c->fd = fd; c->fd = fd;
c->name = NULL; c->name = NULL;
c->bufpos = 0; c->bufpos = 0;
...@@ -1302,7 +1303,8 @@ sds catClientInfoString(sds s, redisClient *client) { ...@@ -1302,7 +1303,8 @@ sds catClientInfoString(sds s, redisClient *client) {
if (emask & AE_WRITABLE) *p++ = 'w'; if (emask & AE_WRITABLE) *p++ = 'w';
*p = '\0'; *p = '\0';
return sdscatfmt(s, 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), getClientPeerId(client),
client->fd, client->fd,
client->name ? (char*)client->name->ptr : "", client->name ? (char*)client->name->ptr : "",
......
...@@ -1451,6 +1451,7 @@ void initServerConfig() { ...@@ -1451,6 +1451,7 @@ void initServerConfig() {
server.lua_client = NULL; server.lua_client = NULL;
server.lua_timedout = 0; server.lua_timedout = 0;
server.migrate_cached_sockets = dictCreate(&migrateCacheDictType,NULL); server.migrate_cached_sockets = dictCreate(&migrateCacheDictType,NULL);
server.next_client_id = 1; /* Client IDs, start from 1 .*/
server.loading_process_events_interval_bytes = (1024*1024*2); server.loading_process_events_interval_bytes = (1024*1024*2);
server.lruclock = getLRUClock(); server.lruclock = getLRUClock();
......
...@@ -492,6 +492,7 @@ typedef struct readyList { ...@@ -492,6 +492,7 @@ typedef struct readyList {
/* With multiplexing we need to take per-client state. /* With multiplexing we need to take per-client state.
* Clients are taken in a liked list. */ * Clients are taken in a liked list. */
typedef struct redisClient { typedef struct redisClient {
uint64_t id; /* Client incremental unique ID. */
int fd; int fd;
redisDb *db; redisDb *db;
int dictid; int dictid;
...@@ -655,6 +656,7 @@ struct redisServer { ...@@ -655,6 +656,7 @@ struct redisServer {
mstime_t clients_pause_end_time; /* Time when we undo clients_paused */ mstime_t clients_pause_end_time; /* Time when we undo clients_paused */
char neterr[ANET_ERR_LEN]; /* Error buffer for anet.c */ char neterr[ANET_ERR_LEN]; /* Error buffer for anet.c */
dict *migrate_cached_sockets;/* MIGRATE cached sockets */ dict *migrate_cached_sockets;/* MIGRATE cached sockets */
uint64_t next_client_id; /* Next client unique ID. Incremental. */
/* RDB / AOF loading information */ /* RDB / AOF loading information */
int loading; /* We are loading data from disk if true */ int loading; /* We are loading data from disk if true */
off_t loading_total_bytes; off_t loading_total_bytes;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment