Commit b8ccffd3 authored by nanahira's avatar nanahira

allow use existing driver

parent 23a06052
...@@ -2,3 +2,4 @@ export * from './src/aragami'; ...@@ -2,3 +2,4 @@ export * from './src/aragami';
export * from './src/def'; export * from './src/def';
export * from './src/decorators'; export * from './src/decorators';
export * from './src/wrappers'; export * from './src/wrappers';
export * from './src/drivers';
import { BaseDriver } from './base-driver'; import { BaseDriver } from './base-driver';
import { AnyClass, AragamiOptions, Awaitable, ClassType } from './def'; import { AnyClass, AragamiOptions, Awaitable, ClassType } from './def';
import { RedisDriver } from './drivers/redis';
import { MemoryDriver } from './drivers/memory';
import { reflector } from './metadata'; import { reflector } from './metadata';
import { encode, decode } from 'encoded-buffer'; import { encode, decode } from 'encoded-buffer';
import { makeArray, MayBeArray } from './utility/utility'; import { makeArray, MayBeArray } from './utility/utility';
import { PartialDeep } from './utility/partial-deep'; import { PartialDeep } from './utility/partial-deep';
import { wrapClass } from './utility/encode-decode'; import { wrapClass } from './utility/encode-decode';
import { MemoryDriver, RedisDriver } from './drivers';
export class Aragami { export class Aragami {
readonly driver: BaseDriver; readonly driver: BaseDriver;
constructor(private options: AragamiOptions = {}) { constructor(private options: AragamiOptions = {}) {
this.driver = options.redis this.driver =
? new RedisDriver(options.redis) options.useDriver ||
: new MemoryDriver(); (options.redis ? new RedisDriver(options.redis) : new MemoryDriver());
} }
private getBaseKey(o: string | any): string { private getBaseKey(o: string | any): string {
......
import { RedisOptions } from 'ioredis'; import { RedisOptions } from 'ioredis';
import { Settings } from '@sesamecare-oss/redlock'; import { Settings } from '@sesamecare-oss/redlock';
import { BaseDriver } from './base-driver';
export type RedisDriverOptions = RedisOptions & { export type RedisDriverOptions = RedisOptions & {
uri?: string; uri?: string;
...@@ -13,6 +14,7 @@ export type RedisDriverOptions = RedisOptions & { ...@@ -13,6 +14,7 @@ export type RedisDriverOptions = RedisOptions & {
}; };
export interface AragamiOptions { export interface AragamiOptions {
useDriver?: BaseDriver;
redis?: RedisDriverOptions; redis?: RedisDriverOptions;
defaultTTL?: number; defaultTTL?: number;
} }
......
export * from './memory';
export * from './redis';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment