SUBSTR(3valkey)
β¨ SUBSTR β the valkey manual, but make it cute β¨
okay so bestie, this is SUBSTR(3valkey) from the Valkey Command Manual, and it's literally the "gimme just part of that string" command. no cap. π
πΈ NAME πΈ
substr β Returns a substring from a string value.
like. you have a string. you want a slice of it. that's the whole vibe. β¨
π SYNOPSIS π
SUBSTR key start end
three lil arguments, no drama, we love to see it π«Ά
π DESCRIPTION π
Returns the substring of the string value stored at key, determined by the offsets start and end (both are inclusive, ok, so end is in the substring, don't come for me).
Negative offsets can be used in order to provide an offset starting from the end of the string. So -1 means the last character, -2 the penultimate and so forth. it's giving "count from the back like a queen" π
The function handles out of range requests by limiting the resulting range to the actual length of the string. so if you ask for way too much, it justβ¦ gives you what exists. no error, no tantrum, just vibes π
π¦ Alternative
GETRANGE
(yes bestie, same energy, different name β GETRANGE is the alternative π)
π REPLY π
valkey-protocol(7) Bulk string reply: the substring of the string value stored at key, determined by the offsets start and end (both are inclusive).
you get a bulk string back. that's it. that's the reply. slay π
π₯ COMPLEXITY π₯
O(N) where N is the length of the returned string. The complexity is ultimately determined by the returned length, but because creating a substring from an existing string is very cheap, it can be considered O(1) for small strings.
ngl that's kinda iconic β the cost is about how much you're handing back, not how big the original was. small strings? basically free. π
π ACL CATEGORIES π
@read@slow@string
π HISTORY π
- Available since: 1.0.0
she's been here since the beginning. main character energy fr fr πβ¨
π§ EXAMPLES π§
127.0.0.1:6379> SET mykey "This is a string"
OK
127.0.0.1:6379> GETRANGE mykey 0 3
"This"
127.0.0.1:6379> GETRANGE mykey -3 -1
"ing"
127.0.0.1:6379> GETRANGE mykey 0 -1
"This is a string"
127.0.0.1:6379> GETRANGE mykey 10 100
"string"
look at her go π 0 3 gives "This", -3 -1 gives "ing", 0 -1 gives the whole entire string back, and 10 100 β way out of range β politely returns "string" instead of losing it. ate. π
π«Ά SEE ALSO π«Ά
append(3valkey), decr(3valkey), decrby(3valkey), delifeq(3valkey), get(3valkey), getdel(3valkey), getex(3valkey), getrange(3valkey), getset(3valkey), incr(3valkey), incrby(3valkey), incrbyfloat(3valkey), lcs(3valkey), mget(3valkey), mset(3valkey), msetnx(3valkey), psetex(3valkey), set(3valkey), setex(3valkey), setnx(3valkey), setrange(3valkey), strlen(3valkey)
the whole string-friend group chat, basically π
okay that's the whole page bestie, go slice some strings π this was 9.0.0, dated 2025-10-21, and that's the SUBSTR(3valkey) moment β periodt. β¨ππ¦
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms