Skip to content

Commit

Permalink
Merge pull request #95 from skgndi12/feature/issue-88/generate-redis-…
Browse files Browse the repository at this point in the history
…client

[#88] Generate Redis client
  • Loading branch information
skgndi12 authored Dec 27, 2023
2 parents be86e45 + 39e3a22 commit f2a0c0a
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
83 changes: 83 additions & 0 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"js-yaml": "^4.1.0",
"jsonwebtoken": "^9.0.2",
"prisma": "^5.5.2",
"redis": "^4.6.12",
"rimraf": "^5.0.0",
"swagger-ui-express": "^5.0.0",
"tsc-alias": "^1.8.5",
Expand Down
25 changes: 25 additions & 0 deletions api/src/infrastructure/redis/redis.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import redis, { RedisClientType, createClient } from 'redis';
import { Logger } from 'winston';

import { RedisConfig } from '@src/infrastructure/repositories/types';

export type RedisClient = RedisClientType<
redis.RedisModules,
redis.RedisFunctions,
redis.RedisScripts
>;

export async function generateRedisClient(
logger: Logger,
config: RedisConfig
): Promise<RedisClient> {
const client = createClient({
url: `redis://:${config.password}@${config.host}:${config.port}`
});

client.on('error', (e) => logger.error('Redis Client Error', { error: e }));

await client.connect();

return client;
}

0 comments on commit f2a0c0a

Please sign in to comment.