In Redis, the OBJECT ENCODING
command returns the internal encoding for the Redis object stored at the specified key.
Syntax
The syntax goes like this:
OBJECT ENCODING key
Where key is the key
that you want to return the internal encoding from.
Example
Suppose we set a couple of keys:
MSET name "Bart" age 10
Result:
OK
We can use the OBJECT ENCODING
command to check their internal encoding.
Here’s the first key:
OBJECT ENCODING name
Result:
"embstr"
This is an embedded string.
And here’s the other one:
OBJECT ENCODING age
Result:
"int"
This is a string that represents an integer.
Let’s try it with a list.
Create the list:
LPUSH pets "Dog" "Cat" "Mouse"
Result:
(integer) 3
Now let’s use OBJECT ENCODING
to get the internal encoding:
OBJECT ENCODING pets
Result:
"quicklist"
See the Redis documentation for an overview of the different encoding methods used for the various data types in Redis.