Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

TAG.SET

Last updated
TAG.SET key tag [tag ...]
Group
Tags
Complexity
O(n), n being the tags
Arity
-3 (at least 3 words, counting the command name)
Flags
write, fast
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

TAG.SET attaches labels to a key, so you can later find keys by label with TAG.MEMBERS and TAG.INTER, or filter vector searches with VSIM.SEARCH FILTER. A key can carry any number of tags, and a tag any number of keys. Tags that the key already has are left as they are.

The key must exist in the selected database when you tag it. Tags work with keys of any type.

  • Tags are kept per key name and shared by all logical databases: tagging user:1 in database 0 also shows up for user:1 in database 1.
  • A key’s tags go when the key does. That covers DEL, UNLINK, GETDEL, expiry, eviction, a command that empties the key (the last element popped from a list, the last member removed from a set, the last field removed from a hash), and FLUSHDB and FLUSHALL. A key created again under the same name starts with no tags. Overwriting a key that still exists, for example with SET, keeps its tags.
  • RENAME and RENAMENX move the tags to the new name, and the tags of a key that a rename replaces are dropped. A RENAMENX that does nothing leaves the tags where they were. MOVE keeps the tags, because tags are shared by all databases.
  • Tags are not part of snapshots, so re-apply them after a server restarts from a snapshot.
Case RESP2 RESP3
Key exists Integer: the number of tags newly attached Integer

Error replies: ERR no such key when the key does not exist.

127.0.0.1:6379> SET article:1 "..."
OK
127.0.0.1:6379> TAG.SET article:1 news sports
(integer) 2
127.0.0.1:6379> TAG.SET article:1 sports europe
(integer) 1
127.0.0.1:6379> TAG.SET article:99 news
(error) ERR no such key

HotKV-only command.

TAG.REM, TAG.GET, TAG.MEMBERS, TAG.INTER, VSIM.SEARCH