# PCACHE.GETEX

> Look up a cached prompt response together with its metadata and hit count.

URL: https://docs.hotkv.com/commands/pcache-getex/

```
PCACHE.GETEX namespace prompt
```

- Group: Prompt cache
- Complexity: O(1)
- HotKV Cloud: Performance and Scale plans
- On-Premise: requires the prompt-cache license feature

The prompt cache is an exact-match cache for LLM prompt and response pairs, organised in named namespaces. `PCACHE.GETEX` works like [PCACHE.GET](https://docs.hotkv.com/commands/pcache-get/index.md), but on a hit it
also returns the metadata stored with `META` and the number of times the
entry has been hit, including this one. In an existing namespace, it counts as
a hit or a miss in
[PCACHE.STATS](https://docs.hotkv.com/commands/pcache-stats/index.md) the same way.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Hit | Array of three elements: the response (bulk string), the metadata (bulk string, empty if none), the hit count (integer) | Same |
| Miss, expired entry, or unknown namespace | Nil bulk string | Null |

Errors:

- `ERR wrong number of arguments for 'pcache.getex' command` if the argument count is wrong.
- `NOLICENSE prompt-cache requires a HotKV license. Contact sales@hotkv.com` if your license does not include the `prompt-cache` feature.

## Examples

```
127.0.0.1:6379> PCACHE.SET llm_prompts "Translate: Hello" "Bonjour" META "{\"lang\":\"fr\"}"
OK
127.0.0.1:6379> PCACHE.GETEX llm_prompts "Translate: Hello"
1) "Bonjour"
2) "{\"lang\":\"fr\"}"
3) (integer) 1
127.0.0.1:6379> PCACHE.GETEX llm_prompts "Translate: Hello"
1) "Bonjour"
2) "{\"lang\":\"fr\"}"
3) (integer) 2
```

## Compatibility

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

## See also

[PCACHE.CREATE](https://docs.hotkv.com/commands/pcache-create/index.md), [PCACHE.SET](https://docs.hotkv.com/commands/pcache-set/index.md), [PCACHE.GET](https://docs.hotkv.com/commands/pcache-get/index.md), [PCACHE.DEL](https://docs.hotkv.com/commands/pcache-del/index.md), [PCACHE.STATS](https://docs.hotkv.com/commands/pcache-stats/index.md), [PCACHE.FLUSH](https://docs.hotkv.com/commands/pcache-flush/index.md), [PCACHE.DROP](https://docs.hotkv.com/commands/pcache-drop/index.md), [PCACHE.LIST](https://docs.hotkv.com/commands/pcache-list/index.md), [PCACHE.CONFIG](https://docs.hotkv.com/commands/pcache-config/index.md), [AI features guide](https://docs.hotkv.com/ai-features/index.md)