UNPKG

@sophons/redis

Version:

🏡 Encapsulate common business methods for Redis

58 lines (57 loc) 2.5 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SuperRedis = void 0; const method_1 = require("./method"); const common_1 = require("./common"); class SuperRedis { constructor(options) { this.client = new common_1.BaseRedis(options); } /** * A message is published to the specified channel */ publish(options) { return __awaiter(this, void 0, void 0, function* () { if (!options || !options.channel || !options.message) return; const { channel, message, setJson } = options; yield this.client.publish(channel, setJson ? JSON.stringify(message) : message); }); } /** * Passing in the function to be executed will add a mutex to the function execution process */ mutex(options) { if (!options || !options.next) throw new Error('Please pass in the function to be executed'); return method_1.mutexDecorator(this.client, options); } /** * Passing in the function to be executed caches the result of the function's execution according to the configuration information */ cache(options) { if (!options || !options.next) throw new Error('Please pass in the function to be executed'); return method_1.cacheDecorator(this.client, options); } /** * Passing in the function to be executed caches the result of the function execution into the hash structure with configuration information */ hashCache(options) { if (!options || !options.next) throw new Error('Please pass in the function to be executed'); return method_1.hashCacheDecorator(this.client, options); } } exports.SuperRedis = SuperRedis;