Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,48 @@ A Redis-based handler for key- and tag-based caching. Compared to the original i
import createRedisHandler from "@fortedigital/nextjs-cache-handler/redis-strings";

const redisHandler = await createRedisHandler({
client,
client: createClient({
url: process.env.REDIS_URL,
}),
keyPrefix: "myApp:",
sharedTagsKey: "myTags",
sharedTagsTtlKey: "myTagTtls",
});
```

#### Redis Cluster (Experimental)

```js
import { createCluster } from "@redis/client";
import createRedisHandler from "@fortedigital/nextjs-cache-handler/redis-strings";
import { withAdapter } from "@fortedigital/nextjs-cache-handler/cluster/adapter";

const { hostname: redisHostName } = new URL(process.env.REDIS_URL);
redis = withAdapter(
createCluster({
rootNodes: [{ url: process.env.REDIS_URL }],

// optional if you use TLS and need to resolve shards' ip to proper hostname
nodeAddressMap(address) {
const [_, port] = address.split(":");

return {
host: redisHostName,
port: Number(port),
};
},
})
);

// after using withAdapter you can use redis cluster instance as parameter for createRedisHandler
const redisCacheHandler = createRedisHandler({
client: redis,
keyPrefix: CACHE_PREFIX,
});
```

**Note:** Redis Cluster support is currently experimental and may have limitations or unexpected bugs. Use it with caution.

---

### `local-lru`
Expand Down Expand Up @@ -186,7 +221,8 @@ Next 15 decided to change types of some properties from String to Buffer which c
```js
import createBufferStringDecoratorHandler from "@fortedigital/nextjs-cache-handler/buffer-string-decorator";

const bufferStringDecorator = createBufferStringDecoratorHandler(redisCacheHandler);
const bufferStringDecorator =
createBufferStringDecoratorHandler(redisCacheHandler);
```

## Examples
Expand Down
2 changes: 1 addition & 1 deletion examples/redis-minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/node": "^24",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint": "^9",
"eslint-config-next": "15.4.3",
"tailwindcss": "^4",
"typescript": "^5"
Expand Down
11 changes: 11 additions & 0 deletions packages/nextjs-cache-handler/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createDefaultPreset } from "ts-jest";

const tsJestTransformCfg = createDefaultPreset().transform;

/** @type {import("jest").Config} **/
export default {
testEnvironment: "node",
transform: {
...tsJestTransformCfg,
},
};
Loading