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.

GUARD.SET

Last updated
GUARD.SET namespace key value [TTL seconds] [MODEL model [INPUT n] [OUTPUT n] [CACHEREAD n] [CACHEWRITE5M n] [CACHEWRITE1H n]]
Group
Keyed caches
Complexity
O(1)
Arity
-4 (at least 4 words, counting the command name)
Flags
write, fast
Keys
first 1, last 1, step 1
HotKV Cloud
Performance and Scale
On-Premise
requires the guard-cache license feature

The guard cache stores only responses that have already passed your schema validation or guardrail checks, so a hit is known to be safe to replay without checking it again. GUARD.SET stores value under key (the prompt or request key) in namespace. If the key is already cached, its value, usage and expiry are replaced. The namespace must exist (see GUARD.CREATE).

Option Effect
TTL seconds Time to live for this entry. 0 or omitted uses the namespace’s default TTL.
MODEL model The model that produced the response. Required when you pass any token count below.
INPUT n Uncached input tokens the original call used.
OUTPUT n Output tokens the original call used.
CACHEREAD n Provider cache-read tokens the original call used.
CACHEWRITE5M n Tokens the original call wrote to a 5-minute provider cache.
CACHEWRITE1H n Tokens the original call wrote to a 1-hour provider cache.

Options come in name and value pairs after value, in any order.

The usage options record what the original, uncached model call consumed. Every later hit on the entry adds those tokens to the namespace’s usage_saved_* counters, and when the model has a price (built in, or set with LLMSTATS.PRICE) it also adds the cost those tokens would have had to usage_saved_cost_usd. Token counts are non-negative integers. Passing a token count without MODEL is rejected.

Case RESP2 RESP3
Entry stored Simple string OK Same

Errors:

  • ERR namespace not found if the namespace does not exist.
  • ERR syntax error if an option has no value.
  • ERR unknown option for any other option name.
  • ERR invalid TTL if TTL is not a non-negative integer.
  • ERR usage token counts (INPUT, OUTPUT, CACHEREAD, CACHEWRITE5M, CACHEWRITE1H) need MODEL if you pass a token count without MODEL.
  • ERR invalid INPUT, ERR invalid OUTPUT, ERR invalid CACHEREAD, ERR invalid CACHEWRITE5M or ERR invalid CACHEWRITE1H if a token count is not a non-negative integer.
  • ERR wrong number of arguments for 'guard.set' command if the argument count is wrong.
  • NOLICENSE guard-cache requires a HotKV license. Contact sales@hotkv.com if your license does not include the guard-cache feature.
127.0.0.1:6379> GUARD.SET validated "Summarize ticket 812 as JSON" "{\"summary\":\"Login fails on Safari\"}"
OK
127.0.0.1:6379> GUARD.SET validated "Summarize ticket 813 as JSON" "{\"summary\":\"Login fails on Safari\"}" TTL 120
OK

HotKV-only command. Redis and Valkey have no equivalent.

GUARD.CREATE, GUARD.GET, GUARD.DEL, GUARD.STATS, GUARD.FLUSH, GUARD.DROP, GUARD.LIST, AI features guide