UNPKG

@fxjs/db-driver

Version:

[![NPM version](https://img.shields.io/npm/v/@fxjs/db-driver.svg)](https://www.npmjs.org/package/@fxjs/db-driver) [![Build Status](https://travis-ci.org/fxjs-modules/db-driver.svg)](https://travis-ci.org/fxjs-modules/db-driver) [![Build status](https://

39 lines (38 loc) 1.32 kB
/// <reference types="fib-pool" /> Object.defineProperty(exports, "__esModule", { value: true }); const db = require("db"); const coroutine = require("coroutine"); const base_class_1 = require("./base.class"); const Utils = require("../utils"); class RedisDriver extends base_class_1.Driver { constructor(conn) { super(conn); this.connection = null; } open() { return super.open(); } close() { if (this.connection) this.connection.close(); } ping() { } command(cmd, ...args) { if (this.isPool) return this.pool(conn => conn.command(cmd, ...args)); if (!this.connection) this.open(); return this.connection.command(cmd, ...args); } commands(cmds, opts) { const { parallel = false } = opts || {}; if (parallel) return coroutine.parallel(Object.keys(cmds), (cmd) => { return { cmd, result: this.command(cmd, ...Utils.arraify(cmds[cmd])) }; }); else return Object.keys(cmds).map((cmd) => { return { cmd, result: this.command(cmd, ...Utils.arraify(cmds[cmd])) }; }); } getConnection() { return db.openRedis(this.uri); } } exports.default = RedisDriver;