ioredis#RedisOptions TypeScript Examples
The following examples show how to use
ioredis#RedisOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From posthog-foss with MIT License | 7 votes |
export async function createRedis(serverConfig: PluginsServerConfig): Promise<Redis.Redis> {
const credentials: Partial<RedisOptions> | undefined = serverConfig.POSTHOG_REDIS_HOST
? {
password: serverConfig.POSTHOG_REDIS_PASSWORD,
port: serverConfig.POSTHOG_REDIS_PORT,
}
: undefined
const redis = new Redis(credentials ? serverConfig.POSTHOG_REDIS_HOST : serverConfig.REDIS_URL, {
...credentials,
maxRetriesPerRequest: -1,
})
let errorCounter = 0
redis
.on('error', (error) => {
errorCounter++
Sentry.captureException(error)
if (errorCounter > REDIS_ERROR_COUNTER_LIMIT) {
status.error('?', 'Redis error encountered! Enough of this, I quit!\n', error)
killGracefully()
} else {
status.error('?', 'Redis error encountered! Trying to reconnect...\n', error)
}
})
.on('ready', () => {
if (process.env.NODE_ENV !== 'test') {
status.info('✅', 'Connected to Redis!')
}
})
await redis.info()
return redis
}
Example #2
Source File: TestConnectionService.ts From rocketredis with MIT License | 6 votes |
export function testConnection(options: RedisOptions): Promise<void> {
return new Promise((resolve, reject) => {
const connection = new Redis(options.port, options.host, {
enableReadyCheck: true,
connectTimeout: 3000,
password: options.password,
retryStrategy() {
return null
}
})
connection.once('ready', () => {
resolve()
connection.disconnect()
})
connection.once('error', () => {
reject(new Error())
})
})
}
Example #3
Source File: throttler-storage-redis.service.ts From nestjs-throttler-storage-redis with MIT License | 6 votes |
constructor(redisOrOptions?: Redis | RedisOptions | string, scanCount?: number) {
this.scanCount = typeof scanCount === 'undefined' ? 1000 : scanCount;
if (redisOrOptions instanceof Redis) {
this.redis = redisOrOptions;
} else if (typeof redisOrOptions === 'string') {
this.redis = new Redis(redisOrOptions as string);
this.disconnectRequired = true;
} else {
this.redis = new Redis(redisOrOptions);
this.disconnectRequired = true;
}
}
Example #4
Source File: redis.ts From hotseat-api with MIT License | 5 votes |
redisConfig: RedisOptions = {
port: Number(process.env.REDIS_PORT) || 6379,
host: process.env.REDIS_HOST || '127.0.0.1',
password:
process.env.NODE_ENV === 'production'
? process.env.REDIS_PASSWORD
: undefined,
}
Example #5
Source File: connection.ts From umbriel with MIT License | 5 votes |
options: RedisOptions = {
host: process.env.REDIS_HOST,
port: Number(process.env.REDIS_PORT ?? 6379),
db: Number(process.env.REDIS_DB ?? 0),
}
Example #6
Source File: throttler-storage-redis.service.ts From nestjs-throttler-storage-redis with MIT License | 5 votes |
constructor(options?: RedisOptions, scanCount?: number);
Example #7
Source File: WorkerQueue.ts From lage with MIT License | 5 votes |
constructor(private config: Pick<Config, "workerQueueOptions" | "concurrency">) {
const redisOptions = config.workerQueueOptions.connection as RedisOptions;
this.coordinatorRedis = new IORedis(redisOptions);
}