Redis - String Getrange Command


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.


Following is the basic syntax of Redis GETRANGE command.

redis> GETRANGE KEY_NAME start end


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

redis> SET mykey "This is my test key" 
redis> GETRANGE mykey 0 3 
redis> GETRANGE mykey 0 -1 
"This is my test key"