Browse Source

Automatically require storage adapter via uri or opts.adapter

emp
Luke Childs 7 years ago
committed by Jytesh
parent
commit
7890a9c367
  1. 18
      packages/keyv/src/index.js

18
packages/keyv/src/index.js

@ -1,9 +1,21 @@
'use strict';
const adapters = {
redis: 'keyv-redis',
mongodb: 'keyv-mongo'
};
class Keyv {
constructor(opts) {
this.opts = opts || {};
this.opts.store = this.opts.store || new Map();
constructor(uri, opts) {
this.opts = Object.assign(
{},
(typeof uri === 'string') ? { uri, adapter: uri.match(/^[^:]*/)[0] } : uri,
opts
);
if (!this.opts.store) {
this.opts.store = this.opts.adapter ? new (require(adapters[this.opts.adapter]))(opts) : new Map();
}
}
get(key) {

Loading…
Cancel
Save