OBJECT encoding

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Get information about a key

Usage is OBJECT encoding key.

encoding data type

  • Strings: int, embstr, raw
  • Lists: before version 3.2.0 ziplist (small lists), linkedlist
    From version 3.2.0 unified as a single quicklist.
  • Sets: intset(integers and small sets), hashtable
  • Sorted Sets: ziplist(small zsets), skiplist
  • Hashes: ziplist(small hashes), hashtable

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

  • int: indicates the value is an integer. Integers with a decimal point are classified as string. If the number starts with 0 it is a string. For example 123 is int and 0123 is embstr.
  • embstr: indicates the value is a string of 44 characters or less. embedded string; embstr is shown from 3.0. Earlier versions showed raw.
  • raw: indicates the value is a string of 45 characters or more.

Example Strings

Command>set key 1234
Result>OK
Command>object encoding key
Result>int
Command>append key Hello
Result>OK
Command>object encoding key
Result>embstr
Command>set key 01234
Result>OK
Command>object encoding key
Result>embstr
Command>set key 12.34
Result>OK
Command>object encoding key
Result>embstr
Command>set key 0123456789012345678901234567890123456789
Result>OK
Command>object encoding key
Result>raw

View animation



Lists data type : ziplist(small lists), linkedlist

  • ziplist: used when there are up to 512 members or the value length is up to 64.
  • linkedlist: used when there are 513 or more members or the value length is 65 or more.
  • This can be set in redis.conf with list-max-ziplist-entries 512, list-max-ziplist-value 64.
  • Before Redis version 3.2.0 these two encoding types were used; from 3.2.0 they are combined into a single quicklist.

Example Lists: before version 3.2.0

Command>llen mylist1
Result>512
Command>object encoding mylist1
Result>ziplist
Command>llen mylist2
Result>513
Command>object encoding mylist2
Result>linkedlist

Example Lists: from version 3.2.0

Command>rpush mylist3 value1 value2
Result>(integer) 2
Command>object encoding mylist3
Result>quicklist


Sets: intset(integers and small sets), hashtable

  • intset: used when all values are integers and there are up to 512 members. If a value starts with 0 or includes a decimal point, it is converted to hashtable.
  • hashtable: used when the value is a string, or there are 513 or more members.
  • This can be set in redis.conf with set-max-intset-entries 512.

Example Sets

Command>sadd myset 1 2 3
Result>3
Command>object encoding mylist1
Result>intset
Command>sadd myset 4.1
Result>1
Command>object encoding myset
Result>hashtable


Sorted Sets: ziplist(small zsets), skiplist

  • ziplist: used when there are up to 128 members or the value length is up to 64.
  • skiplist: used when there are 129 or more members or the value length is 65 or more.
  • This can be set in redis.conf with zset-max-ziplist-entries 128, zset-max-ziplist-value 64.

Example Sets

Command>zcard myzip1
Result>128
Command>object encoding myzip1
Result>ziplist
Command>zcard myzip2
Result>129
Command>object encoding myzip2
Result>skiplist


Hashes: ziplist(small hashes), hashtable

  • ziplist: used when there are up to 512 members or the value length is up to 64.
  • hashtable: used when there are 513 or more members or the value length is 65 or more.
  • This can be set in redis.conf with hash-max-ziplist-entries 512, hash-max-ziplist-value 64.

Example Sets

Command>hlen myhash1
Result>512
Command>object encoding myhash1
Result>ziplist
Command>hlen myhash2
Result>513
Command>object encoding myhash2
Result>hashtable


Syntax

OBJECT encoding key

  • Available since version 2.2.3.
  • Time complexity is O(1)
Related commands TYPE

<< OBJECT OBJECT encoding OBJECT idletime >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.