Redis Keys: OBJECT

Redis OBJECT Command

The Redis OBJECT command is used to inspect the internals of Redis Objects associated with keys. It is useful for debugging or to understand if your keys are using the specially encoded data types to save space.

The OBJECT command supports multiple sub commands:

  • OBJECT REFCOUNT <key> returns the number of references of the value associated with the specified key. This command is mainly useful for debugging.
  • OBJECT ENCODING <key> returns the kind of internal representation used in order to store the value associated with a key.
  • OBJECT IDLETIME <key> returns the number of seconds since the object stored at the specified key is idle. While the value is returned in seconds the actual resolution of this timer is 10 seconds, but may vary in future implementations.

Objects can be encoded in different ways:

  • Strings can be encoded as raw or int.
  • Lists can be encoded as ziplist or linkedlist. The ziplist is the special representation that is used to save space for small lists.
  • Sets can be encoded as intset or hashtable. The intset is a special encoding used for small sets composed solely of integers.
  • Hashes can be encoded as zipmap or hashtable. The zipmap is a special encoding used for small hashes.
  • Sorted Sets can be encoded as ziplist or skiplist format. As for the List type small sorted sets can be specially encoded using ziplist, while the skiplist encoding is the one that works with sorted sets of any size.

Here are some common uses and scenarios for the "OBJECT" command:

  • Memory Usage: Check the memory usage of a specific key with OBJECT ENCODING and OBJECT IDLETIME.
  • Encoding Type: Determine the internal encoding used for a key (e.g., raw, intset).
  • Access Time: Retrieve the time since the last access to a key.
  • Debugging: Gain insights into key internals for debugging and optimization purposes.


OBJECT subcommand [arguments [arguments ...]]

Available since


Return Value

Different return values are used for different subcommands.

  • Subcommands refcount and idletime return integers.
  • Subcommand encoding returns a bulk reply.

If the object you try to inspect is missing, a null bulk reply is returned.

Example: Redis OBJECT refcount key> SET key 0
OK> OBJECT refcount key
(integer) 2> SET key1 0
OK> OBJECT refcount key1
(integer) 3> SET key2 APPLE
OK> OBJECT refcount key2
(integer) 1> SET key3 APPLE
OK> OBJECT refcount key3
(integer) 1

The usage OBJECT encoding key

encoding data type

  • Strings: int, embstr, raw
  • Lists: ziplist (small lists), linkedlist
  • Sets: intset (integers and small sets), hashtable
  • Sorted Sets: ziplist (small sets), skiplist
  • Hashes: zipmap (small hashes), hashtable

Strings data type: int (integer), embstr (small string), raw

  • int: value represents the integer. integer, real (including the decimal point) is classified as a string. If the number starts with a zero string. For example, 123 is int and is a 0123 embstr.
  • embstr: it indicates that the value is string and 39 characters or less. embedded string, embstr is displayed from 3.0. The previous version was shown as raw.
  • raw: value is a string that represents more than 40 characters.

Example: Redis OBJECT encoding> SET key 123
OK> OBJECT encoding key
"int"> APPEND key Apple
(integer) 8> OBJECT encoding key
"raw"> SET key 1234
OK> OBJECT encoding key
"int"> SET key 0123
OK> OBJECT encoding key
"embstr"> SET key 20.34
OK> OBJECT encoding key
"embstr"> SET key 012345678901234567890123456789
OK> OBJECT encoding key
"embstr"> SET key 0123456789012345678901234567890123456789
OK> OBJECT encoding key

The usage OBJECT idletime key

You can find the key is not used for a long time.

Example: Redis OBJECT idletime example> SET key "PHP"
OK> OBJECT idletime key
(integer) 12> APPEND key Tutorial
(integer) 11> OBJECT idletime key
(integer) 13> GET key
"PHPTutorial"> OBJECT idletime key
(integer) 15

Previous: MOVE

Follow us on Facebook and Twitter for latest update.