redis GETRANGE command


  Translation results:

get

英[get] 美[ɡɛt]

vt. Get; catch; persuade; receive (punishment, etc.)

vt.& vi. Arrive, come

vi. Become; start; try to deal with; obtain benefits or wealth

n. Reproduce, cub; profit

Third person singular : gets present participle: getting past tense: got past participle: got gotten

range

##英[reɪndʒ] 美[rendʒ]

n. Range; range; category; (of mountains, houses, etc.) arrangement

vi.Search; change; extension; roaming

vt.Arrangement; (by a certain position or order) sort; put… Classification; wandering

adj. Pasture, grazing area

Third person singular: ranges Plural: ranges Present participle: ranging Past tense: ranged Past participle: ranged

redis GETRANGE commandsyntax

Function: Returns the substring of the string value in key. The interception range of the string is determined by the two offsets of start and end (including start and end).

Syntax: GETRANGE key start end

Description: Negative offset means counting from the end of the string, -1 means the last character , -2 means the second to last, and so on. GETRANGE handles out-of-range range requests by ensuring that the range of the substring does not exceed the range of the actual string. In <= version 2.0, GETRANGE is called SUBSTR.

Available versions: >= 2.4.0

Time complexity: O(N), N is the string to be returned length. The complexity is ultimately determined by the length of the return value of the string, but because the operation of removing a substring from an existing string is very cheap, for strings of small length, the complexity of the operation can also be regarded as O(1).

Return: The intercepted substring.

redis GETRANGE commandexample

redis> SET greeting "hello, my friend"
OK
redis> GETRANGE greeting 0 4          # 返回索引0-4的字符,包括4。
"hello"
redis> GETRANGE greeting -1 -5        # 不支持回绕操作
""
redis> GETRANGE greeting -3 -1        # 负数索引
"end"
redis> GETRANGE greeting 0 -1         # 从第一个到最后一个
"hello, my friend"
redis> GETRANGE greeting 0 1008611    # 值域范围不超过实际字符串,超过部分自动被符略
"hello, my friend"

Home

Videos

Q&A