QRedisCache
@quik/cache / QRedisCache
Class: QRedisCache
Defined in: cache/src/QRedisCache.ts:17
Redis-backed cache implementation using an ioredis client.
Values are serialised as JSON. TTL is forwarded to Redis via the PX option.
The clear() method scans only keys matching the configured prefix.
Example
import { Redis } from "ioredis";
const cache = new QRedisCache(new Redis(), "myapp:cache:");
await cache.set("token", "abc123", 30_000);
Implements
IQCache
Constructors
Constructor
new QRedisCache(
client,prefix?):QRedisCache
Defined in: cache/src/QRedisCache.ts:21
Parameters
client
Redis
prefix?
string = "quik:cache:"
Returns
QRedisCache
Methods
clear()
clear():
Promise<void>
Defined in: cache/src/QRedisCache.ts:85
Delete all keys matching the cache prefix from Redis.
Returns
Promise<void>
Implementation of
IQCache.clear
delete()
delete(
key):Promise<void>
Defined in: cache/src/QRedisCache.ts:68
Remove a value by key.
Parameters
key
string
Cache key.
Returns
Promise<void>
Implementation of
IQCache.delete
get()
get<
T>(key):Promise<T>
Defined in: cache/src/QRedisCache.ts:35
Retrieve a value by key, returning undefined if missing or expired.
Type Parameters
T
T = unknown
Parameters
key
string
Cache key.
Returns
Promise<T>
Implementation of
IQCache.get
has()
has(
key):Promise<boolean>
Defined in: cache/src/QRedisCache.ts:77
Check whether a key exists in Redis.
Parameters
key
string
Cache key.
Returns
Promise<boolean>
Implementation of
IQCache.has
set()
set<
T>(key,value,ttlMs?):Promise<void>
Defined in: cache/src/QRedisCache.ts:54
Store a value by key with an optional TTL.
Type Parameters
T
T = unknown
Parameters
key
string
Cache key.
value
T
Value to store.
ttlMs?
number
Optional time-to-live in milliseconds.
Returns
Promise<void>
Implementation of
IQCache.set