redis-stack
Handler
import { createClient } from 'redis';
import createRedisHandler from '@neshca/cache-handler/redis-stack';
const client = createClient(clientOptions);
await client.connect();
const redisHandler = createRedisHandler({
client,
keyPrefix: 'prefix:',
timeoutMs: 1000,
revalidateTagQuerySize: 100,
});
The redis-stack
Handler uses Redis with RedisJSON
and RedisSearch
modules as the cache store. It is a full-featured cache handler that supports JSON objects and full-text search, offering a trade-off between performance and flexibility. While it may sacrifice some speed compared to the redis-strings
Handler, it empowers you to manage cache on demand more efficiently and faster. It also allows for more versatile cache usage from your application, such as creating custom revalidating strategies and functions. The redis-stack
Handler is suitable for applications that require advanced cache management and search capabilities.
Make sure that you have the RedisJSON
and RedisSearch
modules installed and enabled in your Redis server.
API
@neshca/cache-handler/redis-stack
exports a function that creates a new Handler
instance for the redis-stack
Handler.
Parameters
options
- An object containing the following properties:client
- A Redis client instance. The client must be ready before creating the Handler.keyPrefix
- Optional. Prefix for all keys, useful for namespacing. Defaults to an empty string.timeoutMs
- Optional. Timeout in milliseconds for Redis operations. Defaults to5000
. For disabling timeouts, set it to0
.revalidateTagQuerySize
- Optional. The number of tags in a single query retrieved from Redis when scanning or searching for tags. Defaults to100
.
revalidateTagQuerySize
You can adjust this value to optimize the number of commands sent to Redis when scanning or searching for tags. A higher value will reduce the number of commands sent to Redis, but it will also increase the amount of data transferred over the network. Redis uses TCP and typically has 65,535 bytes as the maximum size of a packet (it can be lower depending on MTU).
Return value
A new Handler
instance for the redis-stack
Handler.