*Redis --- 命令

acl_categories:

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

  • display_text: key key_spec_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 begin_search: spec: index: 1 type: index find_keys: spec: keystep: 1 lastkey: 0 limit: 0 type: range linkTitle: SUBSTR railroad_diagram: /images/railroad/substr.svg replaced_by: 'GETRANGE' since: 1.0.0 summary: 返回字符串值的子串。 syntax_fmt: SUBSTR key start end

    *title: SUBSTR

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

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

*示例

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

*返回信息