Redis getrange 命令用于获取存储在 key 处的字符串值的子字符串,由偏移量 start 和 end 确定(两者都包含,闭区间)。可以使用负偏移量来提供从字符串末尾开始的偏移量。
语法
getrange key_name start end
可用版本
>=2.4.0.返回值
子字符串。
返回值类型
字符串
示例:
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"