Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

refactor: use ioredis #1803

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .config/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ redis:
#path: /var/run/redis/redis-server.sock #unixsocket
host: localhost
port: 6379
#family: 0 # 0=Both, 4=IPv4, 6=IPv6
#pass: example-pass
#prefix: example-prefix
#db: 1
Expand Down
1 change: 1 addition & 0 deletions src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type Source = {
path: string;
host: string;
port: number;
family?: number;
pass: string;
db?: number;
prefix?: string;
Expand Down
21 changes: 10 additions & 11 deletions src/db/redis.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import * as redis from 'redis';
import * as Redis from 'ioredis';
import config from '../config';

export function createConnection() {
if (config.redis.path == null) {
return redis.createClient(
config.redis.port,
config.redis.host,
{
return new Redis({
port: config.redis.port,
host: config.redis.host,
family: config.redis.family == null ? 0 : config.redis.family,
password: config.redis.pass,
prefix: config.redis.prefix,
keyPrefix: `${config.redis.prefix}:`,
db: config.redis.db || 0
}
);
} else {
return redis.createClient(
config.redis.path,
{
return new Redis({
path: config.redis.path,
password: config.redis.pass,
prefix: config.redis.prefix,
keyPrefix: `${config.redis.prefix}:`,
db: config.redis.db || 0
}
);
}
}

export const subsdcriber = createConnection();
subsdcriber.subscribe(config.host);
//subsdcriber.subscribe(config.host);

export const redisClient = createConnection();
2 changes: 2 additions & 0 deletions src/queue/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ if (config.redis.path == null) {
redisOpts = {
port: config.redis.port,
host: config.redis.host,
family: config.redis.family == null ? 0 : config.redis.family,
password: config.redis.pass,
db: config.redis.db || 0,
}
} else {
redisOpts = {
path: config.redis.path,
family: config.redis.family == null ? 0 : config.redis.family,
password: config.redis.pass,
db: config.redis.db || 0,
}
Expand Down