From: antirez Date: Fri, 15 Oct 2010 10:19:21 +0000 (+0200) Subject: added keyspace_hits and keyspace_misses fields in INFO output X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/53eeeaff08eb2268342d3e6a42819207fc618290 added keyspace_hits and keyspace_misses fields in INFO output --- diff --git a/src/db.c b/src/db.c index da7537f4..a39a03bb 100644 --- a/src/db.c +++ b/src/db.c @@ -34,8 +34,10 @@ robj *lookupKey(redisDb *db, robj *key) { if (notify) handleClientsBlockedOnSwappedKey(db,key); } } + server.stat_keyspace_hits++; return val; } else { + server.stat_keyspace_misses++; return NULL; } } diff --git a/src/redis.c b/src/redis.c index 6ce271c0..3defc7f1 100644 --- a/src/redis.c +++ b/src/redis.c @@ -823,6 +823,8 @@ void initServer() { server.stat_numconnections = 0; server.stat_expiredkeys = 0; server.stat_starttime = time(NULL); + server.stat_keyspace_misses = 0; + server.stat_keyspace_hits = 0; server.unixtime = time(NULL); aeCreateTimeEvent(server.el, 1, serverCron, NULL, NULL); if (aeCreateFileEvent(server.el, server.fd, AE_READABLE, @@ -1190,6 +1192,8 @@ sds genRedisInfoString(void) { "total_connections_received:%lld\r\n" "total_commands_processed:%lld\r\n" "expired_keys:%lld\r\n" + "keyspace_hits:%lld\r\n" + "keyspace_misses:%lld\r\n" "hash_max_zipmap_entries:%zu\r\n" "hash_max_zipmap_value:%zu\r\n" "pubsub_channels:%ld\r\n" @@ -1222,6 +1226,8 @@ sds genRedisInfoString(void) { server.stat_numconnections, server.stat_numcommands, server.stat_expiredkeys, + server.stat_keyspace_hits, + server.stat_keyspace_misses, server.hash_max_zipmap_entries, server.hash_max_zipmap_value, dictSize(server.pubsub_channels), diff --git a/src/redis.h b/src/redis.h index 9b16b024..d6bdcb20 100644 --- a/src/redis.h +++ b/src/redis.h @@ -357,12 +357,14 @@ struct redisServer { aeEventLoop *el; int cronloops; /* number of times the cron function run */ list *objfreelist; /* A list of freed objects to avoid malloc() */ - time_t lastsave; /* Unix time of last save succeeede */ + time_t lastsave; /* Unix time of last save succeeede */ /* Fields used only for stats */ - time_t stat_starttime; /* server start time */ - long long stat_numcommands; /* number of processed commands */ - long long stat_numconnections; /* number of connections received */ - long long stat_expiredkeys; /* number of expired keys */ + time_t stat_starttime; /* server start time */ + long long stat_numcommands; /* number of processed commands */ + long long stat_numconnections; /* number of connections received */ + long long stat_expiredkeys; /* number of expired keys */ + long long stat_keyspace_hits; /* number of successful lookups of keys */ + long long stat_keyspace_misses; /* number of failed lookups of keys */ /* Configuration */ int verbosity; int glueoutputbuf;