GETRANGE

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

Get a substring

Specify start and end.
The leftmost (front) character of the string starts at 0.
The specified indexes are inclusive.
end is a position, not the length of the string.

Example

Command>set key "This is Redis Server"
Result>OK
Command>getrange key 0 3
Result>This
Command>getrange key 8 12
Result>Redis
Command>getrange key 8 100
Result>Redis Server


Negative indexes are allowed

Use a negative index to read from the end of the string.
The last character starts at -1.

Example

Command>getrange key -6 -1
Result>Server
Command>getrange key 0 -1   Use 0 -1 to get the entire string
Result>This is Redis Server


Syntax

GETRANGE key start end

  • Available since version 2.4.0.
  • Added as SUBSTR in version 2.0 and renamed to GETRANGE in 2.4.
  • Time complexity depends on the returned string.
    Treat it as O(N) when the returned string is long, and O(1) when it is short.
Related commands SET, SETRANGE, STRLEN
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< SETRANGE GETRANGE STRALGO >>

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