# TagCache.set() method · @imqueue/tag-cache

Source: https://imqueue.org/api/tag-cache/latest/tag-cache.tagcache.set/
Published: 2026-07-31
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/tag-cache 3.0.3 — generated reference, not hand-written

Stores given value under a given key, tagging it with the given tags

The value is JSON-encoded, and the key is added to one redis set per tag so [TagCache.invalidate()](https://imqueue.org/api/tag-cache/latest/tag-cache.tagcache.invalidate/) can find it later. Everything happens in a single `MULTI`, so a value is never visible without its tag membership.

When `ttl` is given it is applied to the value AND refreshed on each tag set, so tag sets do not outlive the entries they track. Without it, nothing expires and the entry lives until it is invalidated.

**Signature:**

```typescript
set<_T = any>(key: string, value: any, tags: string[], ttl?: number): Promise<boolean>;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| key | string | unprefixed key to store the value under |
| value | any | data to store; must be JSON-serialisable |
| tags | string\[\] | tags to mark the value with; any one of them can later invalidate it. An empty array stores the value with no tag, which makes it unreachable by [TagCache.invalidate()](https://imqueue.org/api/tag-cache/latest/tag-cache.tagcache.invalidate/). |
| ttl | number | _(Optional)_ optional time to live, in MILLISECONDS |


**Returns:**

Promise<boolean>

`true` once the write is committed, `false` if redis rejected it — the error is logged rather than thrown

## Exceptions

TypeError when there is no redis connection — see [REDIS\_INIT\_ERROR](https://imqueue.org/api/tag-cache/latest/tag-cache.redis_init_error/)

