UNPKG

adonis5-cache

Version:
41 lines (40 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class RedisStorage { constructor(redisConnection) { this.redisConnection = redisConnection; } async get(context, key) { const cacheValue = await this.redisConnection.get(key); return cacheValue !== null ? context.deserialize(cacheValue) : cacheValue; } async getMany(context, keys) { return Promise.all(keys.map((key) => this.get(context, key))); } async put(context, key, value, ttl) { await this.redisConnection.psetex(key, ttl, context.serialize(value)); } async putMany(context, cacheDictionary, ttl) { await Promise.all(Object.entries(cacheDictionary).map(([key, value]) => this.put(context, key, value, ttl))); } async flush() { await this.redisConnection.flushdb(); } async forget(key) { const result = await this.redisConnection.del(key); return Boolean(result); } async addTag(tag, tagData) { await this.redisConnection.sadd(tag, tagData); } async readTag(tag) { return this.redisConnection.smembers(tag); } async removeTag(tag) { await this.redisConnection.del(tag); } resolveTtl(ttlInMl) { return ttlInMl; } } exports.default = RedisStorage;