@replicode/redis
Advanced tools
Comparing version
export interface RedisOptions { | ||
api_key: string; | ||
connection_string: string; | ||
} | ||
export declare const defaultRedisOptions: RedisOptions; | ||
//# sourceMappingURL=redis.options.d.ts.map |
@@ -5,4 +5,4 @@ "use strict"; | ||
exports.defaultRedisOptions = { | ||
api_key: '' | ||
connection_string: '' | ||
}; | ||
//# sourceMappingURL=redis.options.js.map |
import { RedisOptions } from './redis.options'; | ||
import { RedisClientType } from 'redis'; | ||
export declare class RedisService { | ||
private options; | ||
private logger; | ||
client: RedisClientType; | ||
constructor(options: Partial<RedisOptions>); | ||
redisConnect(): Promise<void>; | ||
initialize(): Promise<void>; | ||
} | ||
//# sourceMappingURL=redis.service.d.ts.map |
@@ -15,6 +15,23 @@ "use strict"; | ||
const redis_options_1 = require("./redis.options"); | ||
const redis_1 = require("redis"); | ||
let RedisService = class RedisService { | ||
constructor(options) { | ||
this.logger = new common_1.Logger('RedisService'); | ||
this.options = Object.assign({}, redis_options_1.defaultRedisOptions, options); | ||
this.initialize(); | ||
} | ||
async redisConnect() { | ||
this.client.connect().catch(error => { | ||
this.logger.log(`Redis error on connect: ${error}`); | ||
}); | ||
} | ||
async initialize() { | ||
this.client = (0, redis_1.createClient)({ url: this.options.connection_string }); | ||
this.redisConnect(); | ||
this.client.on('error', async (err) => { | ||
this.logger.log(`Redis error: ${err}`); | ||
await this.client.disconnect(); | ||
this.redisConnect(); | ||
}); | ||
} | ||
}; | ||
@@ -21,0 +38,0 @@ RedisService = __decorate([ |
{ | ||
"name": "@replicode/redis", | ||
"version": "1.0.0", | ||
"version": "1.0.01", | ||
"description": "", | ||
@@ -16,2 +16,3 @@ "main": "dist/index", | ||
"@nestjs/common": "^9.0.5", | ||
"redis": "^4.2.0", | ||
"rxjs": "^7.5.6" | ||
@@ -18,0 +19,0 @@ }, |
export interface RedisOptions { | ||
api_key:string; | ||
connection_string:string; | ||
} | ||
export const defaultRedisOptions: RedisOptions = { | ||
api_key: '' | ||
connection_string: '' | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { | ||
@@ -6,2 +6,3 @@ defaultRedisOptions, | ||
} from './redis.options'; | ||
import { createClient, RedisClientType } from 'redis'; | ||
@@ -11,3 +12,6 @@ @Injectable() | ||
private options: RedisOptions; | ||
private logger: Logger = new Logger('RedisService'); | ||
public client:RedisClientType; | ||
constructor(options: Partial<RedisOptions>) { | ||
@@ -19,4 +23,24 @@ this.options = Object.assign( | ||
); | ||
this.initialize(); | ||
} | ||
async redisConnect() { | ||
this.client.connect().catch(error => { | ||
this.logger.log(`Redis error on connect: ${error}`); | ||
}) | ||
} | ||
async initialize() { | ||
this.client = createClient({ url: this.options.connection_string }); | ||
this.redisConnect(); | ||
this.client.on('error', async (err) => { | ||
this.logger.log(`Redis error: ${err}`); | ||
await this.client.disconnect(); | ||
this.redisConnect(); | ||
}); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
11367
24.91%197
25.48%3
50%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added