🎉 1.3.0 is out! It features the new keyExpirationStrategy option for the redis-strings Handler!
Handlers
redis-strings

redis-strings Handler

import createRedisHandler from '@neshca/cache-handler/redis-strings';
 
// ...
await client.connect();
 
const redisHandler = createRedisHandler({
  client,
  keyPrefix: 'JSON:',
  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 to 5000.
    • keyExpirationStrategy - Optional. It allows you to choose the expiration strategy for cache keys. Defaults to EXPRIREAT.
    • 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 to 100.

keyExpirationStrategy

  • 'EXAT': Uses the EXAT option of the SET command to set the expiration time. This is more efficient than EXPIREAT. Requires Redis server 6.2.0 or newer
  • 'EXPIREAT': Uses the EXPIREAT 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.