SREM(3valkey)
π SREM β ok bestie, we're yeeting members out of a set π
So this is SREM from the Valkey Command Manual, page SREM(3valkey), and it's genuinely one of the most satisfying commands in the whole toolkit. Let's get into it π«Ά
β¨ NAME β¨
srem β Removes one or more members from a set. Deletes the set if the last member was removed.
Like. It doesn't just take the member out, it also cleans up the whole set if that was the last one standing. Very "and I took that personally" of it. π
πΈ SYNOPSIS πΈ
SREM key member [member...]
π¦ DESCRIPTION π¦
Okay so here's the tea: SREM removes the specified members from the set stored at key.
Specified members that are not a member of this set? Ignored. No drama, no error, they just get a lil shrug. π
And if key doesn't exist at all? It's treated as an empty set, and this command returns 0. Chillest behaviour ever, honestly.
β οΈ But β and this is the important part β an error is returned when the value stored at key is not a set. So don't come at it with a string, bestie, it will not play nice. π
π REPLY π
valkey-protocol(7) Integer reply: the number of members that were actually removed from the set β and this does not include non existing members. So if you ask it to remove five things and three of them weren't there, you're getting a 3, periodt.
β COMPLEXITY β
O(N) where N is the number of members to be removed. Linear girlie, but only over the members you're actually asking about. Slay. π₯
π ACL CATEGORIES π
@fast @set @write
π HISTORY π
- Available since: 1.0.0
- Changed in 2.4.0: Accepts multiple member arguments. (Yes queen, before that it was one member at a time β we've come so far π)
π EXAMPLES π
127.0.0.1:6379> SADD myset "one"
(integer) 1
127.0.0.1:6379> SADD myset "two"
(integer) 1
127.0.0.1:6379> SADD myset "three"
(integer) 1
127.0.0.1:6379> SREM myset "one"
(integer) 1
127.0.0.1:6379> SREM myset "four"
(integer) 0
127.0.0.1:6379> SMEMBERS myset
1) "two"
2) "three"
See how SREM myset "one" came back with (integer) 1 because "one" was actually in there? And then SREM myset "four" came back with (integer) 0 because "four" was never invited to the function? That's the whole vibe check right there. β¨
π§ SEE ALSO π§
sadd(3valkey), scard(3valkey), sdiff(3valkey), sdiffstore(3valkey), sinter(3valkey), sintercard(3valkey), sinterstore(3valkey), sismember(3valkey), smembers(3valkey), smismember(3valkey), smove(3valkey), spop(3valkey), srandmember(3valkey), sscan(3valkey), sunion(3valkey), sunionstore(3valkey)
and that's the whole page, bestie π This one's from Valkey 9.0.0, dated 2025-10-21, filed under SREM(3valkey). Go forth and remove members with main character energy. Mwah π
π¦ 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