Redis – String Getrange Command

  • Post author:
  • Post category:Redis
  • Post comments:0 Comments

Redis GETRANGE command is used to get the substring of the string value stored at the key, determined by the offsets start and end (both are inclusive). Negative offsets can be used in order to provide an offset starting from the end of the string.

The function handles out of range requests by limiting the resulting range to the actual length of the string.

Return Value

Simple string reply.

Syntax

Following is the basic syntax of Redis GETRANGE command.

redis 127.0.0.1:6379> GETRANGE KEY_NAME start end

Example

First, set a key in Redis and then get some part of it.

redis 127.0.0.1:6379> SET mykey "This is my test key" 
OK 
redis 127.0.0.1:6379> GETRANGE mykey 0 3 
"This" 
redis 127.0.0.1:6379> GETRANGE mykey 0 -1 
"This is my test key"

Leave a Reply