GETRANGE

Syntax
GETRANGE key start end
Available since:
2.4.0
Time complexity:
O(N) where N is the length of the returned string. The complexity is ultimately determined by the returned length, but because creating a substring from an existing string is very cheap, it can be considered O(1) for small strings.
ACL categories:
@read, @string, @slow,

返回存储在key中的字符串值的子字符串,由偏移量startend(两者都包括在内)确定。 可以使用负偏移量来提供从字符串末尾开始的偏移量。 因此,-1表示最后一个字符,-2表示倒数第二个字符,依此类推。

该函数通过将结果范围限制为字符串的实际长度来处理超出范围的请求。

示例

SET mykey "This is a string" GETRANGE mykey 0 3 GETRANGE mykey -3 -1 GETRANGE mykey 0 -1 GETRANGE mykey 10 100

RESP2/RESP3 回复

Bulk string reply: The substring of the string value stored at key, determined by the offsets start and end (both are inclusive).
RATE THIS PAGE
Back to top ↑