File tree Expand file tree Collapse file tree 4 files changed +34
-7
lines changed
Expand file tree Collapse file tree 4 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,20 @@ services:
44 ports :
55 - ' 6379:6379'
66
7+ redis-cluster :
8+ profiles :
9+ - cluster
10+ image : grokzen/redis-cluster:7.0.8
11+ environment :
12+ - IP=0.0.0.0
13+ - INITIAL_PORT=7000
14+ - MASTERS=3
15+ - SLAVES_PER_MASTER=0
16+ ports :
17+ - ' 7000:7000'
18+ - ' 7001:7001'
19+ - ' 7002:7002'
20+
721 redis-insight :
822 image : redis/redisinsight:latest
923 ports :
Original file line number Diff line number Diff line change 1- import { Redis as IoRedis } from 'ioredis'
21import type { RedisOptions as IoRedisOptions } from 'ioredis'
32import { RedisTransport } from '@boringnode/bus/transports/redis'
3+ import { Redis as IoRedis , Cluster as IoRedisCluster } from 'ioredis'
44import type { RedisTransportConfig } from '@boringnode/bus/types/main'
55
66import { BaseDriver } from './base_driver.js'
@@ -43,13 +43,13 @@ export function redisBusDriver(
4343 */
4444export class RedisDriver extends BaseDriver implements L2CacheDriver {
4545 type = 'l2' as const
46- #connection: IoRedis
46+ #connection: IoRedis | IoRedisCluster
4747 declare config : RedisConfig
4848
4949 constructor ( config : RedisConfig ) {
5050 super ( config )
5151
52- if ( config . connection instanceof IoRedis ) {
52+ if ( config . connection instanceof IoRedis || config . connection instanceof IoRedisCluster ) {
5353 this . #connection = config . connection
5454 return
5555 }
Original file line number Diff line number Diff line change 11import type { Knex } from 'knex'
22import type { Kysely } from 'kysely'
33import type { DynamoDBClientConfig } from '@aws-sdk/client-dynamodb'
4- import type { Redis as IoRedis , RedisOptions as IoRedisOptions } from 'ioredis'
54import type { DbResult , DefaultColumnTypes , DefaultSchemaConfig } from 'orchid-orm'
5+ import type {
6+ Redis as IoRedis ,
7+ RedisOptions as IoRedisOptions ,
8+ Cluster as IoRedisCluster ,
9+ } from 'ioredis'
610
711import type { Logger } from '../../logger.js'
812import type { Duration } from '../helpers.js'
@@ -105,9 +109,9 @@ export type MemoryConfig = {
105109 */
106110export type RedisConfig = {
107111 /**
108- * A IoRedis connection instance or connection options
112+ * A IoRedis connection instance (Redis or Cluster) or connection options
109113 */
110- connection : IoRedis | IoRedisOptions
114+ connection : IoRedis | IoRedisCluster | IoRedisOptions
111115} & DriverCommonOptions
112116
113117/**
Original file line number Diff line number Diff line change 11import { test } from '@japa/runner'
2- import { Redis as IoRedis } from 'ioredis'
2+ import { Redis as IoRedis , Cluster as IoRedisCluster } from 'ioredis'
33
44import { REDIS_CREDENTIALS } from '../helpers/index.js'
55import { RedisDriver } from '../../src/drivers/redis.js'
@@ -23,6 +23,15 @@ test.group('Redis driver', (group) => {
2323 await ioredis . quit ( )
2424 } )
2525
26+ test ( 'should be able to provide an instance of ioredis cluster' , async ( { assert } ) => {
27+ const cluster = new IoRedisCluster ( [ { host : '127.0.0.1' , port : 7000 } ] )
28+ const redis = new RedisDriver ( { connection : cluster } )
29+
30+ assert . equal ( redis . getConnection ( ) , cluster )
31+
32+ await redis . disconnect ( )
33+ } ) . skip ( ! ! process . env . CI , 'Skipping cluster test on CI' )
34+
2635 test ( 'should works with ioredis keyPrefix' , async ( { assert } ) => {
2736 const ioredis = new IoRedis ( { ...REDIS_CREDENTIALS , keyPrefix : 'test:' } )
2837 const ioRedis2 = new IoRedis ( { ...REDIS_CREDENTIALS } )
You can’t perform that action at this time.
0 commit comments