GETRANGE

AttentionThis page documents an earlier version. Go to the latest (v2.1)version.

Synopsis

GETRANGE key start endThis command fetches a substring of the string value that is associated with the given key between the two given offsets start and end. If an offset value is positive, it is counted from the beginning of the string. If an offset is negative, it is counted from the end. If an offset is out of range, it is limited to either the beginning or the end of the string.

  • If key does not exist, (null) is returned.
  • If key is associated with a non-string value, an error is raised.

Return Value

Returns a string value.

Examples

You can do this as shown below.

  1. $ SET yugakey "Yugabyte"
  1. "OK"
  1. $ GETRANGE yugakey 0 3
  1. "Yuga"
  1. $ GETRANGE yugakey -4 -1
  1. "Byte"

See Also

append, get, getset, incr, incrby, set, setrange, strlen