STRLEN

Redis Developer Course Redis Cloud Service Redis-Gate Server

Returns the bytes(length) of the value of a key

Return value

Integer reply, specifically:

  • number: bytes of the string at key
  • 0 if the key does not exist in the database
  • -WRONGTYPE Operation against a key holding the wrong kind of value: if the data type of the key is not STRINGS

Example

command>set key value
result>OK
command>strlen key
result>5
command>append key 1234567890
result>15
command>get key
result>value1234567890
command>strlen key
result>15
command>set key 100
result>OK
command>incr key
result>101
command>strlen key
result>3


UTF-8 Korean, Japanese, Chinese

Korean, Japanese, and Chinese of UTF-8, there are 3 bytes in one character.

Example

command>set key 대한민국
result>OK
command>strlen key
result>12
command>set key 日本
result>OK
command>strlen key
result>6
command>set key 中华人民共和国
result>OK
command>strlen key
result>21
Note You can not use Korean, Japanese, and Chinese in redis-cli,
but you can use any language in Redis Web Client provided by this site.


Syntax

STRLEN key

  • Available since 2.2.0.
  • Time complexity(Logical processing time): O(1)
Related Commands SET, SETRANGE, GETRANGE
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

To practice the command, click here to run Redis Web Client


<< APPEND STRLEN SETRANGE >>

Click for a question or to see comments.  Comments :    Viewed :

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