Object command allows to inspect the internals of a Redis Object. * Usage: OBJECT */
| 1253 | /* Object command allows to inspect the internals of a Redis Object. |
| 1254 | * Usage: OBJECT <refcount|encoding|idletime|freq> <key> */ |
| 1255 | void objectCommand(client *c) { |
| 1256 | robj *o; |
| 1257 | |
| 1258 | if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"help")) { |
| 1259 | const char *help[] = { |
| 1260 | "ENCODING <key>", |
| 1261 | " Return the kind of internal representation used in order to store the value", |
| 1262 | " associated with a <key>.", |
| 1263 | "FREQ <key>", |
| 1264 | " Return the access frequency index of the <key>. The returned integer is", |
| 1265 | " proportional to the logarithm of the recent access frequency of the key.", |
| 1266 | "IDLETIME <key>", |
| 1267 | " Return the idle time of the <key>, that is the approximated number of", |
| 1268 | " seconds elapsed since the last access to the key.", |
| 1269 | "REFCOUNT <key>", |
| 1270 | " Return the number of references of the value associated with the specified", |
| 1271 | " <key>.", |
| 1272 | NULL |
| 1273 | }; |
| 1274 | addReplyHelp(c, help); |
| 1275 | } else if (!strcasecmp(c->argv[1]->ptr,"refcount") && c->argc == 3) { |
| 1276 | if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.null[c->resp])) |
| 1277 | == NULL) return; |
| 1278 | addReplyLongLong(c,o->refcount); |
| 1279 | } else if (!strcasecmp(c->argv[1]->ptr,"encoding") && c->argc == 3) { |
| 1280 | if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.null[c->resp])) |
| 1281 | == NULL) return; |
| 1282 | addReplyBulkCString(c,strEncoding(o->encoding)); |
| 1283 | } else if (!strcasecmp(c->argv[1]->ptr,"idletime") && c->argc == 3) { |
| 1284 | if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.null[c->resp])) |
| 1285 | == NULL) return; |
| 1286 | if (server.maxmemory_policy & MAXMEMORY_FLAG_LFU) { |
| 1287 | addReplyError(c,"An LFU maxmemory policy is selected, idle time not tracked. Please note that when switching between policies at runtime LRU and LFU data will take some time to adjust."); |
| 1288 | return; |
| 1289 | } |
| 1290 | addReplyLongLong(c,estimateObjectIdleTime(o)/1000); |
| 1291 | } else if (!strcasecmp(c->argv[1]->ptr,"freq") && c->argc == 3) { |
| 1292 | if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.null[c->resp])) |
| 1293 | == NULL) return; |
| 1294 | if (!(server.maxmemory_policy & MAXMEMORY_FLAG_LFU)) { |
| 1295 | addReplyError(c,"An LFU maxmemory policy is not selected, access frequency not tracked. Please note that when switching between policies at runtime LRU and LFU data will take some time to adjust."); |
| 1296 | return; |
| 1297 | } |
| 1298 | /* LFUDecrAndReturn should be called |
| 1299 | * in case of the key has not been accessed for a long time, |
| 1300 | * because we update the access time only |
| 1301 | * when the key is read or overwritten. */ |
| 1302 | addReplyLongLong(c,LFUDecrAndReturn(o)); |
| 1303 | } else { |
| 1304 | addReplySubcommandSyntaxError(c); |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | /* The memory command will eventually be a complete interface for the |
| 1309 | * memory introspection capabilities of Redis. |
nothing calls this directly
no test coverage detected