Redis Cluster Adapter
Package: @nauth-toolkit/storage-redis
Type: Storage Adapter (Production HA)
High-availability Redis Cluster storage for production deployments.
- npm
- Yarn
- pnpm
- Bun
npm install @nauth-toolkit/storage-redis redis
yarn add @nauth-toolkit/storage-redis redis
pnpm add @nauth-toolkit/storage-redis redis
bun add @nauth-toolkit/storage-redis redis
Usage
- NestJS
- Express
- Fastify
import { createCluster } from 'redis';
import { RedisStorageAdapter } from '@nauth-toolkit/storage-redis';
const clusterClient = createCluster({
rootNodes: [
{ url: 'redis://node1:6379' },
{ url: 'redis://node2:6379' },
{ url: 'redis://node3:6379' },
],
});
await clusterClient.connect();
AuthModule.forRoot({
storageAdapter: new RedisStorageAdapter(clusterClient),
})
Or with factory:
import { createRedisClusterAdapter } from '@nauth-toolkit/nestjs';
AuthModule.forRoot({
storageAdapter: createRedisClusterAdapter([
{ url: 'redis://node1:6379' },
{ url: 'redis://node2:6379' },
{ url: 'redis://node3:6379' },
]),
})
import { createCluster } from 'redis';
import { RedisStorageAdapter } from '@nauth-toolkit/storage-redis';
const clusterClient = createCluster({
rootNodes: [
{ url: 'redis://node1:6379' },
{ url: 'redis://node2:6379' },
{ url: 'redis://node3:6379' },
],
});
await clusterClient.connect();
const nauth = await NAuth.create({
config: {
storageAdapter: new RedisStorageAdapter(clusterClient),
},
// ...
});
import { createCluster } from 'redis';
import { RedisStorageAdapter } from '@nauth-toolkit/storage-redis';
import { FastifyAdapter } from '@nauth-toolkit/core';
const clusterClient = createCluster({
rootNodes: [
{ url: 'redis://node1:6379' },
{ url: 'redis://node2:6379' },
{ url: 'redis://node3:6379' },
],
});
await clusterClient.connect();
const nauth = await NAuth.create({
config: {
storageAdapter: new RedisStorageAdapter(clusterClient),
},
adapter: new FastifyAdapter(),
// ...
});
Features
- High availability (automatic failover)
- Horizontal scaling
- Same
RedisStorageAdapterclass as single instance - Uses
createCluster()instead ofcreateClient()
Related
- Redis - Single instance
- Session Storage