SUBSTR(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

✨ 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