TAG.SET
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.
How tags behave
Section titled “How tags behave”- Tags are kept per key name and shared by all logical databases:
tagging
user:1in database 0 also shows up foruser:1in 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
RENAMENXthat 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.
Return value
Section titled “Return value”| 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.
Examples
Section titled “Examples”127.0.0.1:6379> SET article:1 "..."OK127.0.0.1:6379> TAG.SET article:1 news sports(integer) 2127.0.0.1:6379> TAG.SET article:1 sports europe(integer) 1127.0.0.1:6379> TAG.SET article:99 news(error) ERR no such keyCompatibility
Section titled “Compatibility”HotKV-only command.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.