mikro-orm-cache-adapter-redis
Advanced tools
Comparing version 0.1.0 to 0.1.1
import { CacheAdapter } from '@mikro-orm/core'; | ||
import { RedisOptions } from 'ioredis'; | ||
interface RedisCacheAdapterOptions extends RedisOptions { | ||
debug?: boolean; | ||
} | ||
export default class RedisCacheAdapter implements CacheAdapter { | ||
private readonly client; | ||
constructor(options: RedisOptions); | ||
private readonly debug; | ||
constructor(options: RedisCacheAdapterOptions); | ||
get(key: string): Promise<any>; | ||
@@ -10,1 +14,2 @@ set(name: string, data: any, origin: string, expiration?: number): Promise<void>; | ||
} | ||
export {}; |
@@ -38,2 +38,13 @@ "use strict"; | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -46,3 +57,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
function RedisCacheAdapter(options) { | ||
var _a = options.debug, debug = _a === void 0 ? false : _a, redisOpt = __rest(options, ["debug"]); | ||
this.client = new ioredis_1.default(options); | ||
this.debug = debug; | ||
} | ||
@@ -57,2 +70,5 @@ RedisCacheAdapter.prototype.get = function (key) { | ||
data = _a.sent(); | ||
if (this.debug) { | ||
console.log("get \"" + key + "\": \"" + data + "\""); | ||
} | ||
if (!data) | ||
@@ -70,2 +86,5 @@ return [2 /*return*/, null]; | ||
case 0: | ||
if (this.debug) { | ||
console.log("set \"" + name + "\": \"" + data + "\" with expiration " + expiration); | ||
} | ||
if (!expiration) return [3 /*break*/, 2]; | ||
@@ -89,3 +108,7 @@ return [4 /*yield*/, this.client.set(name, JSON.stringify(data), 'PX', expiration)]; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.client.flushdb()]; | ||
case 0: | ||
if (this.debug) { | ||
console.log('clear cache'); | ||
} | ||
return [4 /*yield*/, this.client.flushdb()]; | ||
case 1: | ||
@@ -92,0 +115,0 @@ _a.sent(); |
{ | ||
"name": "mikro-orm-cache-adapter-redis", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A redis cache adapter for mikro-orm", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
8781
146