UNPKG

@dazejs/framework

Version:

Daze.js - A powerful web framework for Node.js

46 lines 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Redis = void 0; const helpers_1 = require("../../helpers"); const connector_1 = require("./connector"); const fake_base_class_1 = require("../../utils/fake-base-class"); class Redis extends (0, fake_base_class_1.fakeBaseClass)() { constructor() { super(); this.instances = new Map(); return new Proxy(this, this.proxy); } get proxy() { return { get(target, p, receiver) { if (typeof p === 'string') { if (Reflect.has(target, p)) { return Reflect.get(target, p, receiver); } return target.connection()[p]; } return Reflect.get(target, p, receiver); } }; } connection(name = 'default') { if (!this.instances.has(name)) { const config = this.getConnectioncConfigure(name); const instance = this.createConnection(config); instance && this.instances.set(name, instance); } return this.instances.get(name); } getConnectioncConfigure(name) { const options = (0, helpers_1.config)().get(`redis.${name}`); if (!options) throw new Error(`未找到 Redis 配置 [redis.${name}]`); return options; } createConnection(options) { const redis = (new connector_1.Connector()).connect(options); return redis; } } exports.Redis = Redis; //# sourceMappingURL=redis.js.map