nestjs-request-deduplication
Version:
[](https://www.npmjs.com/package/nestjs-request-deduplication) [](https://gith
43 lines (42 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedisAdapter = void 0;
const tslib_1 = require("tslib");
const keyv_1 = tslib_1.__importDefault(require("keyv"));
const redis_1 = tslib_1.__importDefault(require("@keyv/redis"));
const common_1 = require("@nestjs/common");
class RedisAdapter {
constructor(options) {
this.options = options;
this.logger = new common_1.Logger(RedisAdapter.name);
}
init() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
this.keyv = new keyv_1.default({
store: new redis_1.default(this.options.redisConfig),
namespace: 'request-deduplication',
});
this.logger.log('Redis storage adapter initialized successfully');
});
}
get(key) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const value = yield this.keyv.get(key);
if (value === undefined) {
throw new Error(`Key ${key} not found`);
}
return value;
});
}
set(key, value, ttl) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.keyv.set(key, value, ttl);
});
}
delete(key) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.keyv.delete(key);
});
}
}
exports.RedisAdapter = RedisAdapter;