redis-strings
Handler
import { createClient } from 'redis';
import createRedisHandler from '@neshca/cache-handler/redis-strings';
const client = createClient(clientOptions);
await client.connect();
const redisHandler = createRedisHandler({
client,
keyPrefix: 'prefix:',
timeoutMs: 1000,
keyExpirationStrategy: 'EXAT',
sharedTagsKey: '__sharedTags__',
revalidateTagQuerySize: 100,
});
The redis-strings
Handler uses plain Redis as the cache store. It is a simple and fast cache handler that is suitable for most applications. This Handler is ideal for applications that require fast and efficient cache management without the need for advanced features like full-text search for custom revalidation strategies.
API
@neshca/cache-handler/redis-strings
exports a function that creates a new Handler
instance for the redis-strings
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
.keyExpirationStrategy
- Optional. It allows you to choose the expiration strategy for cache keys. Defaults toEXPRIREAT
.sharedTagsKey
- Optional. Dedicated key for the internal revalidation process. It must not interfere with cache keys from your application. Defaults to__sharedTags__
.revalidateTagQuerySize
- Optional. The number of tags in a single query retrieved from Redis when scanning or searching for tags. Defaults to100
.
keyExpirationStrategy
'EXAT'
: Uses theEXAT
option of theSET
command to set the expiration time. This is more efficient thanEXPIREAT
. Requires Redis server 6.2.0 or newer'EXPIREAT'
: Uses theEXPIREAT
command to set the expiration time. This requires an additional command call. Requires Redis server 4.0.0 or newer.
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-strings
Handler.