RedisCache
RedisCache
A cache provider that uses Redis as the cache store.
Example
const redisCache = new RedisCache();
new CommandKit({
...
cacheProvider: redisCache,
});
Signature
class RedisCache extends CacheProvider {
public redis: Redis;
public serialize: SerializeFunction;
public deserialize: DeserializeFunction;
constructor()
constructor(redis: Redis)
constructor(redis: RedisOptions)
constructor(redis?: Redis | RedisOptions)
get(key: string) => Promise<CacheEntry<T> | undefined>;
set(key: string, value: T, ttl?: number) => Promise<void>;
clear() => Promise<void>;
delete(key: string) => Promise<void>;
exists(key: string) => Promise<boolean>;
expire(key: string, ttl: number) => Promise<void>;
}
- Extends:
CacheProvider
redis
property
Redis
serialize
property
Serialize function used to serialize values before storing them in the cache.
By default, it uses JSON.stringify
.
deserialize
property
Deserialize function used to deserialize values before returning them from the cache.
By default, it uses JSON.parse
.
constructor
method
() => RedisCache
Create a new RedisCache instance.
constructor
method
(redis: Redis) => RedisCache
Create a new RedisCache instance with the provided Redis client.
constructor
method
(redis: RedisOptions) => RedisCache
Create a new RedisCache instance with the provided Redis options.
constructor
method
(redis?: Redis | RedisOptions) => RedisCache
get
method
(key: string) => Promise<CacheEntry<T> | undefined>
Retrieve a value from the cache.
set
method
(key: string, value: T, ttl?: number) => Promise<void>
Store a value in the cache.
clear
method
() => Promise<void>
Clear all entries from the cache.
delete
method
(key: string) => Promise<void>
Delete a value from the cache.
exists
method
(key: string) => Promise<boolean>
Check if a value exists in the cache.
expire
method
(key: string, ttl: number) => Promise<void>
Set the time-to-live for a cache entry.