菜鸟笔记
提升您的技术认知

Redis Getrange 命令

阅读 : 914

Redis 字符串(String)

Redis Getrange 命令用于获取存储在指定 key 中字符串的子字符串。字符串的截取范围由 start 和 end 两个偏移量决定(包括 start 和 end 在内)。

语法

redis Getrange 命令基本语法如下:

redis 127.0.0.1:6379> GETRANGE KEY_NAME start end

可用版本

>= 2.4.0

返回值

截取得到的子字符串。

实例

首先,设置 coonotekey 的值并截取字符串。

redis 127.0.0.1:6379> SET coonotekey "This is my test key"
OK
redis 127.0.0.1:6379> GETRANGE coonotekey 0 3
"This"
redis 127.0.0.1:6379> GETRANGE coonotekey 0 -1
"This is my test key"

Redis 字符串(String)