*Redis --- 命令

acl_categories:

  • '@read'
  • '@string'
  • '@slow' arguments:

  • displaytext: key keyspec_index: 0 name: key type: key

  • display_text: start name: start type: integer

  • display_text: end name: end type: integer arity: 4 categories:

  • docs

  • develop

  • stack

  • oss

  • rs

  • rc

  • oss

  • kubernetes

  • clients command_flags:

  • readonly complexity: O(N) 其中 N 是返回字符串的长度。复杂度最终由返回长度决定,但由于从现有字符串创建子字符串非常便宜,对于小字符串可以视为 O(1)。 description: 返回字符串值的子串。 doc_flags:

  • deprecated group: string hidden: false key_specs:

  • RO: true access: true beginsearch: spec: index: 1 type: index findkeys: spec: keystep: 1 lastkey: 0 limit: 0 type: range linkTitle: SUBSTR railroaddiagram: /images/railroad/substr.svg replacedby: 'GETRANGE' since: 1.0.0 summary: 返回字符串值的子串。 syntax_fmt: SUBSTR key start end

    *title: SUBSTR

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

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

*示例

redis> SET mykey "This is a string"
"OK"
redis> GETRANGE mykey 0 3
"This"
redis> GETRANGE mykey -3 -1
"ing"
redis> GETRANGE mykey 0 -1
"This is a string"
redis> GETRANGE mykey 10 100
"string"
redis>

*返回信息