无涯教程-Redis - GETRANGE 命令函数

145 阅读1分钟

Redis GETRANGE 命令用于获取键处存储的字符串值的子字符串,该子字符串由偏移量start和end(包括两端)确定,可以使用负偏移量来提供从字符串末尾开始的偏移量。

GETRANGE - 返回值

简单的字符串回复。

GETRANGE - 语法

以下是Redis GETRANGE 命令的基本语法。

redis 127.0.0.1:6379> GETRANGE KEY_NAME start end

GETRANGE - 示例

首先,在Redis中设置一个键(key),然后获取其中的一部分。

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"

参考链接

www.learnfk.com/redis/strin…