@adonisjs/redis
Advanced tools
Comparing version 3.0.0 to 3.1.0
/// <reference types="ioredis" /> | ||
/// <reference types="node" /> | ||
declare module '@ioc:Adonis/Addons/Redis' { | ||
import Emittery from 'emittery'; | ||
import { EventEmitter } from 'events'; | ||
import { Redis, RedisOptions, ClusterOptions, Cluster, NodeRole } from 'ioredis'; | ||
type ConnectionsList = Exclude<keyof RedisConfigContract, 'connection'>; | ||
type GetFactory<T extends ConnectionsList> = RedisConfigContract[T] extends ClusterConfigContract ? RedisClusterFactoryContract : RedisFactoryContract; | ||
export interface RedisConnectionsList { | ||
} | ||
type GetFactory<T extends keyof RedisConnectionsList> = RedisConnectionsList[T] extends ClusterConfigContract ? RedisClusterFactoryContract : RedisFactoryContract; | ||
export type ReportNode = { | ||
connection: string; | ||
status: string; | ||
used_memory: string; | ||
error: any; | ||
}; | ||
export type PubSubChannelHandler<T extends any = any> = ((data: T) => Promise<void> | void); | ||
@@ -20,6 +30,9 @@ export type PubSubPatternHandler<T extends any = any> = ((channel: string, data: T) => Promise<void> | void); | ||
clusterOptions?: ClusterOptions; | ||
healthCheck?: boolean; | ||
}; | ||
export type ConnectionConfigContract = RedisOptions; | ||
export type RedisCommandsContract = Omit<Redis, 'Promise' | 'status' | 'connect' | 'disconnect' | 'duplicate' | 'subscribe' | 'unsubscribe' | 'psubscribe' | 'punsubscribe' | 'quit'>; | ||
export interface RedisFactoryContract extends RedisCommandsContract, RedisPubSubContract { | ||
export type ConnectionConfigContract = RedisOptions & { | ||
healthCheck?: boolean; | ||
}; | ||
export type RedisCommandsContract = Omit<Redis, 'Promise' | 'status' | 'connect' | 'disconnect' | 'duplicate' | 'subscribe' | 'unsubscribe' | 'psubscribe' | 'punsubscribe' | 'quit' | keyof EventEmitter>; | ||
export interface RedisFactoryContract extends RedisCommandsContract, RedisPubSubContract, Emittery { | ||
status: string; | ||
@@ -33,5 +46,22 @@ connectionName: string; | ||
duplicate(): Redis; | ||
getReport(checkForMemory?: boolean): Promise<ReportNode>; | ||
quit(): Promise<void>; | ||
on(event: 'connect', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'ready', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'error', callback: ((data: [this, any]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'close', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'reconnecting', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'end', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:connect', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:ready', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:error', callback: ((data: [this, any]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:close', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:reconnecting', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:end', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscription:error', callback: ((data: [this, any]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscription:ready', callback: ((data: [this, number]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'psubscription:error', callback: ((data: [this, any]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'psubscription:ready', callback: ((data: [this, number]) => any)): Emittery.UnsubscribeFn; | ||
} | ||
export interface RedisClusterFactoryContract extends RedisCommandsContract, RedisPubSubContract { | ||
export interface RedisClusterFactoryContract extends RedisCommandsContract, RedisPubSubContract, Emittery { | ||
status: string; | ||
@@ -42,2 +72,3 @@ connectionName: string; | ||
ioSubscriberConnection?: Cluster; | ||
getReport(checkForMemory?: boolean): Promise<ReportNode>; | ||
connect(callback?: () => void): Promise<any>; | ||
@@ -48,13 +79,62 @@ nodes(role?: NodeRole): Redis[]; | ||
quit(): Promise<void>; | ||
on(event: 'connect', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'ready', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'error', callback: ((data: [this, any]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'close', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'reconnecting', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'end', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:connect', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:ready', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:error', callback: ((data: [this, any]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:close', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:reconnecting', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:end', callback: ((data: [this]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscription:error', callback: ((data: [this, any]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscription:ready', callback: ((data: [this, number]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'psubscription:error', callback: ((data: [this, any]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'psubscription:ready', callback: ((data: [this, number]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'node:added', callback: ((data: [this, Redis]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'node:removed', callback: ((data: [this, Redis]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'node:error', callback: ((data: [this, any, string]) => any)): Emittery.UnsubscribeFn; | ||
} | ||
export interface RedisConfigContract { | ||
connection: ConnectionsList; | ||
connection: keyof RedisConnectionsList; | ||
connections: { | ||
[P in keyof RedisConnectionsList]: RedisConnectionsList[P]; | ||
}; | ||
} | ||
export interface RedisContract extends Omit<GetFactory<RedisConfigContract['connection']>, 'status' | 'connectionName' | 'subscriberStatus' | 'ioConnection' | 'ioSubscriberConnection' | 'duplicate' | 'disconnect' | 'quit'> { | ||
connection<Connection extends ConnectionsList>(name: Connection): GetFactory<Connection>; | ||
type Factory = RedisFactoryContract | RedisClusterFactoryContract; | ||
export interface RedisContract extends Emittery { | ||
on(event: 'connect', callback: ((data: [Factory]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'ready', callback: ((data: [Factory]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'error', callback: ((data: [Factory, any]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'close', callback: ((data: [Factory]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'reconnecting', callback: ((data: [Factory]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'end', callback: ((data: [Factory]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:connect', callback: ((data: [Factory]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:ready', callback: ((data: [Factory]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:error', callback: ((data: [Factory, any]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:close', callback: ((data: [Factory]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:reconnecting', callback: ((data: [Factory]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscriber:end', callback: ((data: [Factory]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscription:error', callback: ((data: [Factory, any]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'subscription:ready', callback: ((data: [Factory, number]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'psubscription:error', callback: ((data: [Factory, any]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'psubscription:ready', callback: ((data: [Factory, number]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'node:added', callback: ((data: [Factory, Redis]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'node:removed', callback: ((data: [Factory, Redis]) => any)): Emittery.UnsubscribeFn; | ||
on(event: 'node:error', callback: ((data: [Factory, any, string]) => any)): Emittery.UnsubscribeFn; | ||
connection<Connection extends keyof RedisConnectionsList>(name: Connection): GetFactory<Connection>; | ||
connection(name: string): RedisFactoryContract | RedisClusterFactoryContract; | ||
connection(): GetFactory<RedisConfigContract['connection']>; | ||
quit<Connection extends ConnectionsList>(name: Connection): Promise<void>; | ||
report(): Promise<{ | ||
health: { | ||
healthy: boolean; | ||
message: string; | ||
}; | ||
meta: ReportNode[]; | ||
}>; | ||
quit<Connection extends keyof RedisConnectionsList>(name: Connection): Promise<void>; | ||
quit(name?: string): Promise<void>; | ||
disconnect<Connection extends ConnectionsList>(name: Connection): Promise<void>; | ||
disconnect<Connection extends keyof RedisConnectionsList>(name: Connection): Promise<void>; | ||
disconnect(name?: string): Promise<void>; | ||
@@ -61,0 +141,0 @@ quitAll(): Promise<void>; |
@@ -0,5 +1,6 @@ | ||
import { IocContract } from '@adonisjs/fold'; | ||
export default class RedisProvider { | ||
protected $container: any; | ||
constructor($container: any); | ||
protected $container: IocContract; | ||
constructor($container: IocContract); | ||
register(): void; | ||
} |
@@ -10,6 +10,4 @@ "use strict"; | ||
this.$container.singleton('Adonis/Addons/Redis', () => { | ||
const config = this.$container.use('Adonis/Src/Config'); | ||
return new Redis_1.Redis(config.get('redis', { | ||
connection: 'primary', | ||
})); | ||
const config = this.$container.use('Adonis/Core/Config').get('redis', {}); | ||
return new Redis_1.Redis(this.$container, config); | ||
}); | ||
@@ -16,0 +14,0 @@ } |
/// <reference path="../../adonis-typings/redis.d.ts" /> | ||
import * as Emitter from 'emittery'; | ||
import Emitter from 'emittery'; | ||
import { Redis, Cluster } from 'ioredis'; | ||
import { PubSubChannelHandler, PubSubPatternHandler } from '@ioc:Adonis/Addons/Redis'; | ||
import { IocContract } from '@adonisjs/fold'; | ||
import { PubSubChannelHandler, PubSubPatternHandler, ReportNode } from '@ioc:Adonis/Addons/Redis'; | ||
export declare abstract class AbstractFactory<T extends (Redis | Cluster)> extends Emitter { | ||
@@ -11,8 +12,11 @@ connectionName: string; | ||
protected $psubscriptions: Map<string, PubSubPatternHandler>; | ||
private _namespace; | ||
private _deferredReportAttempts; | ||
private _lastError?; | ||
private _resolver; | ||
private _resolveIoCBinding; | ||
private _getUsedMemory; | ||
readonly status: string; | ||
readonly subscriberStatus: string | undefined; | ||
protected abstract $makeSubscriberConnection(): void; | ||
constructor(connectionName: string); | ||
constructor(connectionName: string, container: IocContract); | ||
protected $proxyConnectionEvents(): void; | ||
@@ -26,2 +30,3 @@ protected $setupSubscriberConnection(): void; | ||
punsubscribe(pattern: string): any; | ||
getReport(checkForMemory?: boolean): Promise<ReportNode>; | ||
} |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Emitter = require("emittery"); | ||
const emittery_1 = __importDefault(require("emittery")); | ||
const utils_1 = require("@poppinss/utils"); | ||
class AbstractFactory extends Emitter { | ||
constructor(connectionName) { | ||
const sleep = () => new Promise((resolve) => setTimeout(resolve, 1000)); | ||
class AbstractFactory extends emittery_1.default { | ||
constructor(connectionName, container) { | ||
super(); | ||
@@ -11,11 +15,15 @@ this.connectionName = connectionName; | ||
this.$psubscriptions = new Map(); | ||
this._namespace = 'App/Listeners'; | ||
this._deferredReportAttempts = 0; | ||
this._resolver = container.getResolver(undefined, 'redisListeners', 'App/Listeners'); | ||
} | ||
_resolveIoCBinding(handler) { | ||
const parsed = utils_1.parseIocReference(handler, this._namespace); | ||
return function dynamicEventHandler(...args) { | ||
const instance = global[Symbol.for('ioc.make')](parsed.namespace); | ||
return global[Symbol.for('ioc.call')](instance, parsed.method, args); | ||
return (...args) => { | ||
return this._resolver.call(handler, undefined, args); | ||
}; | ||
} | ||
async _getUsedMemory() { | ||
const memory = await this.ioConnection.info('memory'); | ||
const memorySegment = memory.split(/\r|\r\n/).find((line) => line.trim().startsWith('used_memory_human')); | ||
return memorySegment ? memorySegment.split(':')[1] : 'unknown'; | ||
} | ||
get status() { | ||
@@ -31,11 +39,17 @@ return this.ioConnection.status; | ||
$proxyConnectionEvents() { | ||
this.ioConnection.on('connect', () => this.emit('connect')); | ||
this.ioConnection.on('ready', () => this.emit('ready')); | ||
this.ioConnection.on('error', (error) => this.emit('error', error)); | ||
this.ioConnection.on('close', () => this.emit('close')); | ||
this.ioConnection.on('reconnecting', () => this.emit('reconnecting')); | ||
this.ioConnection.on('+node', (node) => this.emit('node:added', node)); | ||
this.ioConnection.on('-node', (node) => this.emit('node:removed', node)); | ||
this.ioConnection.on('connect', () => this.emit('connect', [this])); | ||
this.ioConnection.on('ready', () => { | ||
this._lastError = null; | ||
this.emit('ready', [this]); | ||
}); | ||
this.ioConnection.on('error', (error) => { | ||
this._lastError = error; | ||
this.emit('error', [this, error]); | ||
}); | ||
this.ioConnection.on('close', () => this.emit('close', [this])); | ||
this.ioConnection.on('reconnecting', () => this.emit('reconnecting', [this])); | ||
this.ioConnection.on('+node', (node) => this.emit('node:added', [this, node])); | ||
this.ioConnection.on('-node', (node) => this.emit('node:removed', [this, node])); | ||
this.ioConnection.on('node error', (error, address) => { | ||
this.emit('node:error', { error, address }); | ||
this.emit('node:error', [this, error, address]); | ||
}); | ||
@@ -45,3 +59,3 @@ this.ioConnection.on('end', async () => { | ||
try { | ||
await this.emit('end', this); | ||
await this.emit('end', [this]); | ||
} | ||
@@ -70,11 +84,11 @@ catch (error) { | ||
}); | ||
this.ioSubscriberConnection.on('connect', () => this.emit('subscriber:connect')); | ||
this.ioSubscriberConnection.on('ready', () => this.emit('subscriber:ready')); | ||
this.ioSubscriberConnection.on('error', (error) => this.emit('subscriber:error', error)); | ||
this.ioSubscriberConnection.on('close', () => this.emit('subscriber:close')); | ||
this.ioSubscriberConnection.on('reconnecting', () => this.emit('subscriber:reconnecting')); | ||
this.ioSubscriberConnection.on('connect', () => this.emit('subscriber:connect', [this])); | ||
this.ioSubscriberConnection.on('ready', () => this.emit('subscriber:ready', [this])); | ||
this.ioSubscriberConnection.on('error', (error) => this.emit('subscriber:error', [this, error])); | ||
this.ioSubscriberConnection.on('close', () => this.emit('subscriber:close', [this])); | ||
this.ioSubscriberConnection.on('reconnecting', () => this.emit('subscriber:reconnecting', [this])); | ||
this.ioSubscriberConnection.on('end', async () => { | ||
this.ioConnection.removeAllListeners(); | ||
try { | ||
await this.emit('subscriber:end', this); | ||
await this.emit('subscriber:end', [this]); | ||
} | ||
@@ -106,3 +120,3 @@ catch (error) { | ||
if (error) { | ||
this.emit('subscription:error', error); | ||
this.emit('subscription:error', [this, error]); | ||
return; | ||
@@ -113,3 +127,3 @@ } | ||
} | ||
this.emit('subscription:ready', count); | ||
this.emit('subscription:ready', [this, count]); | ||
this.$subscriptions.set(channel, handler); | ||
@@ -129,3 +143,3 @@ }); | ||
if (error) { | ||
this.emit('psubscription:error', error); | ||
this.emit('psubscription:error', [this, error]); | ||
return; | ||
@@ -136,3 +150,3 @@ } | ||
} | ||
this.emit('psubscription:ready', count); | ||
this.emit('psubscription:ready', [this, count]); | ||
this.$psubscriptions.set(pattern, handler); | ||
@@ -145,3 +159,37 @@ }); | ||
} | ||
async getReport(checkForMemory) { | ||
const connection = this.ioConnection; | ||
if (connection.status === 'connecting' && this._deferredReportAttempts < 3 && !this._lastError) { | ||
await sleep(); | ||
this._deferredReportAttempts++; | ||
return this.getReport(checkForMemory); | ||
} | ||
if (!['ready', 'connect'].includes(connection.status)) { | ||
return { | ||
connection: this.connectionName, | ||
status: connection.status, | ||
used_memory: 'unknown', | ||
error: this._lastError, | ||
}; | ||
} | ||
try { | ||
await connection.ping(); | ||
const memory = checkForMemory ? await this._getUsedMemory() : 'unknown'; | ||
return { | ||
connection: this.connectionName, | ||
status: connection.status, | ||
used_memory: memory, | ||
error: null, | ||
}; | ||
} | ||
catch (error) { | ||
return { | ||
connection: this.connectionName, | ||
status: connection.status, | ||
used_memory: 'unknown', | ||
error, | ||
}; | ||
} | ||
} | ||
} | ||
exports.AbstractFactory = AbstractFactory; |
/// <reference path="../../adonis-typings/redis.d.ts" /> | ||
export declare class Redis { | ||
import Emitter from 'emittery'; | ||
import { IocContract } from '@adonisjs/fold'; | ||
import { RedisConfigContract, RedisContract, ReportNode } from '@ioc:Adonis/Addons/Redis'; | ||
export declare class Redis extends Emitter implements RedisContract { | ||
private _container; | ||
private _config; | ||
private _connectionPools; | ||
private _cleanup; | ||
constructor(_config: any); | ||
private _healthCheckConnections; | ||
constructor(_container: IocContract, _config: RedisConfigContract); | ||
private _getDefaultConnection; | ||
private _getExistingConnection; | ||
connection(connection?: string): any; | ||
private _getConnectionConfig; | ||
connection(name?: string): any; | ||
quit(connection?: string): Promise<void>; | ||
disconnect(connection?: string): Promise<void>; | ||
quitAll(): Promise<void[]>; | ||
disconnectAll(): Promise<void[]>; | ||
quitAll(): Promise<void>; | ||
disconnectAll(): Promise<void>; | ||
report(): Promise<{ | ||
health: { | ||
healthy: boolean; | ||
message: string; | ||
}; | ||
meta: ReportNode[]; | ||
}>; | ||
} |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const emittery_1 = __importDefault(require("emittery")); | ||
const utils_1 = require("@poppinss/utils"); | ||
const RedisFactory_1 = require("../RedisFactory"); | ||
const RedisClusterFactory_1 = require("../RedisClusterFactory"); | ||
const ioMethods_1 = require("../ioMethods"); | ||
class Redis { | ||
constructor(_config) { | ||
class Redis extends emittery_1.default { | ||
constructor(_container, _config) { | ||
super(); | ||
this._container = _container; | ||
this._config = _config; | ||
this._connectionPools = {}; | ||
this._cleanup = function cleanup(connection) { | ||
delete this._connectionPools[connection.connectionName]; | ||
}.bind(this); | ||
this._healthCheckConnections = Object.keys(this._config.connections) | ||
.filter((connection) => this._config.connections[connection].healthCheck); | ||
} | ||
@@ -22,15 +26,23 @@ _getDefaultConnection() { | ||
} | ||
connection(connection) { | ||
connection = connection || this._getDefaultConnection(); | ||
if (this._connectionPools[connection]) { | ||
return this._connectionPools[connection]; | ||
_getConnectionConfig(name) { | ||
return this._config.connections[name]; | ||
} | ||
connection(name) { | ||
name = name || this._getDefaultConnection(); | ||
if (this._connectionPools[name]) { | ||
return this._connectionPools[name]; | ||
} | ||
const config = this._config[connection]; | ||
const config = this._getConnectionConfig(name); | ||
if (!config) { | ||
throw new utils_1.Exception(`Define config for ${connection} connection inside config/redis file`); | ||
throw new utils_1.Exception(`Define config for ${name} connection inside config/redis file`); | ||
} | ||
const factory = this._connectionPools[connection] = config.clusters | ||
? new RedisClusterFactory_1.RedisClusterFactory(connection, config) | ||
: new RedisFactory_1.RedisFactory(connection, config); | ||
factory.on('end', this._cleanup); | ||
const factory = this._connectionPools[name] = config.clusters | ||
? new RedisClusterFactory_1.RedisClusterFactory(name, config, this._container) | ||
: new RedisFactory_1.RedisFactory(name, config, this._container); | ||
factory.on('end', ([connection]) => { | ||
delete this._connectionPools[connection.connectionName]; | ||
}); | ||
factory.onAny((event, data) => { | ||
this.emit(event, data); | ||
}); | ||
return factory; | ||
@@ -53,13 +65,21 @@ } | ||
async quitAll() { | ||
return Promise.all(Object.keys(this._connectionPools).map((name) => this.quit(name))); | ||
await Promise.all(Object.keys(this._connectionPools).map((name) => this.quit(name))); | ||
} | ||
async disconnectAll() { | ||
return Promise.all(Object.keys(this._connectionPools).map((name) => this.disconnect(name))); | ||
await Promise.all(Object.keys(this._connectionPools).map((name) => this.disconnect(name))); | ||
} | ||
async report() { | ||
const reports = await Promise.all(this._healthCheckConnections.map((connection) => { | ||
return this.connection(connection).getReport(true); | ||
})); | ||
const healthy = !reports.find((report) => !!report.error); | ||
return { | ||
health: { | ||
healthy, | ||
message: healthy ? 'All connections are healthy' : 'One or more redis connections are not healthy', | ||
}, | ||
meta: reports, | ||
}; | ||
} | ||
} | ||
exports.Redis = Redis; | ||
ioMethods_1.ioMethods.forEach((method) => { | ||
Redis.prototype[method] = function redisProxyFn(...args) { | ||
return this.connection()[method](...args); | ||
}; | ||
}); |
/// <reference path="../../adonis-typings/redis.d.ts" /> | ||
import * as Redis from 'ioredis'; | ||
import Redis from 'ioredis'; | ||
import { IocContract } from '@adonisjs/fold'; | ||
import { ClusterConfigContract } from '@ioc:Adonis/Addons/Redis'; | ||
@@ -7,5 +8,5 @@ import { AbstractFactory } from '../AbstractFactory'; | ||
private _config; | ||
constructor(connectionName: string, _config: ClusterConfigContract); | ||
constructor(connectionName: string, _config: ClusterConfigContract, container: IocContract); | ||
protected $makeSubscriberConnection(): void; | ||
nodes(role?: Redis.NodeRole): Redis.Redis[]; | ||
} |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Redis = require("ioredis"); | ||
const ioredis_1 = __importDefault(require("ioredis")); | ||
const ioMethods_1 = require("../ioMethods"); | ||
const AbstractFactory_1 = require("../AbstractFactory"); | ||
class RedisClusterFactory extends AbstractFactory_1.AbstractFactory { | ||
constructor(connectionName, _config) { | ||
super(connectionName); | ||
constructor(connectionName, _config, container) { | ||
super(connectionName, container); | ||
this._config = _config; | ||
this.ioConnection = new Redis.Cluster(this._config.clusters, this._config.clusterOptions); | ||
this.ioConnection = new ioredis_1.default.Cluster(this._config.clusters, this._config.clusterOptions); | ||
this.$proxyConnectionEvents(); | ||
} | ||
$makeSubscriberConnection() { | ||
this.ioSubscriberConnection = new Redis.Cluster(this._config.clusters, this._config.clusterOptions); | ||
this.ioSubscriberConnection = new ioredis_1.default.Cluster(this._config.clusters, this._config.clusterOptions); | ||
} | ||
@@ -16,0 +19,0 @@ nodes(role) { |
/// <reference path="../../adonis-typings/redis.d.ts" /> | ||
import * as Redis from 'ioredis'; | ||
import Redis from 'ioredis'; | ||
import { IocContract } from '@adonisjs/fold'; | ||
import { ConnectionConfigContract } from '@ioc:Adonis/Addons/Redis'; | ||
@@ -7,4 +8,4 @@ import { AbstractFactory } from '../AbstractFactory'; | ||
private _config; | ||
constructor(connectionName: string, _config: ConnectionConfigContract); | ||
constructor(connectionName: string, _config: ConnectionConfigContract, container: IocContract); | ||
protected $makeSubscriberConnection(): void; | ||
} |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Redis = require("ioredis"); | ||
const ioredis_1 = __importDefault(require("ioredis")); | ||
const ioMethods_1 = require("../ioMethods"); | ||
const AbstractFactory_1 = require("../AbstractFactory"); | ||
class RedisFactory extends AbstractFactory_1.AbstractFactory { | ||
constructor(connectionName, _config) { | ||
super(connectionName); | ||
constructor(connectionName, _config, container) { | ||
super(connectionName, container); | ||
this._config = _config; | ||
this.ioConnection = new Redis(this._config); | ||
this.ioConnection = new ioredis_1.default(this._config); | ||
this.$proxyConnectionEvents(); | ||
} | ||
$makeSubscriberConnection() { | ||
this.ioSubscriberConnection = new Redis(this._config); | ||
this.ioSubscriberConnection = new ioredis_1.default(this._config); | ||
} | ||
@@ -16,0 +19,0 @@ } |
{ | ||
"name": "@adonisjs/redis", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "AdonisJs addon for Redis", | ||
"main": "build/index.js", | ||
"files": [ | ||
"build/adonis-typings", | ||
"build/providers", | ||
"build/src", | ||
"build/adonis-typings", | ||
"build/providers" | ||
"build/templates" | ||
], | ||
"types": "build/adonis-typings/index.d.ts", | ||
"types": "build/adonis-typings/redis.d.ts", | ||
"scripts": { | ||
@@ -18,4 +19,5 @@ "mrm": "mrm --preset=@adonisjs/mrm-preset", | ||
"clean": "del build", | ||
"copyfiles": "copyfiles \"templates/**/*.txt\" build", | ||
"compile": "npm run lint && npm run clean && tsc", | ||
"build": "npm run compile", | ||
"build": "npm run compile && npm run copyfiles", | ||
"commit": "git-cz", | ||
@@ -44,17 +46,20 @@ "release": "np", | ||
"devDependencies": { | ||
"@adonisjs/fold": "^6.0.3", | ||
"@adonisjs/mrm-preset": "^2.0.3", | ||
"@types/node": "^12.0.10", | ||
"commitizen": "^3.1.1", | ||
"cz-conventional-changelog": "^2.1.0", | ||
"del-cli": "^2.0.0", | ||
"@adonisjs/fold": "^6.1.9", | ||
"@adonisjs/mrm-preset": "^2.1.0", | ||
"@adonisjs/sink": "^2.1.11", | ||
"@poppinss/application": "^1.0.10", | ||
"@types/node": "^12.7.4", | ||
"commitizen": "^4.0.3", | ||
"copyfiles": "^2.1.1", | ||
"cz-conventional-changelog": "^3.0.2", | ||
"del-cli": "^3.0.0", | ||
"doctoc": "^1.4.0", | ||
"husky": "^2.5.0", | ||
"japa": "^2.0.10", | ||
"husky": "^3.0.5", | ||
"japa": "^3.0.1", | ||
"mrm": "^1.2.2", | ||
"np": "^5.0.3", | ||
"ts-node": "^8.3.0", | ||
"tslint": "^5.18.0", | ||
"tslint": "^5.20.0", | ||
"tslint-eslint-rules": "^5.4.0", | ||
"typescript": "^3.5.2" | ||
"typescript": "^3.6.2" | ||
}, | ||
@@ -85,7 +90,32 @@ "nyc": { | ||
"dependencies": { | ||
"@poppinss/utils": "^1.0.3", | ||
"@types/ioredis": "^4.0.12", | ||
"@poppinss/utils": "^2.0.0", | ||
"@types/ioredis": "^4.0.17", | ||
"emittery": "^0.4.1", | ||
"ioredis": "^4.10.0" | ||
"ioredis": "^4.14.0" | ||
}, | ||
"peerDependencies": { | ||
"@adonisjs/core": "2.x.x" | ||
}, | ||
"adonisjs": { | ||
"templates": { | ||
"config": [ | ||
{ | ||
"src": "config.txt", | ||
"dest": "redis" | ||
} | ||
], | ||
"constracts": [ | ||
{ | ||
"src": "contract.txt", | ||
"dest": "redis" | ||
} | ||
] | ||
}, | ||
"env": { | ||
"REDIS_CONNECTION": "default", | ||
"REDIS_HOST": "127.0.0.1", | ||
"REDIS_PORT": "6379", | ||
"REDIS_PASSWORD": "" | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
35736
19
728
0
5
18
+ Added@adonisjs/ace@6.9.4(transitive)
+ Added@adonisjs/application@1.3.16(transitive)
+ Added@adonisjs/bodyparser@3.2.7(transitive)
+ Added@adonisjs/config@1.1.0(transitive)
+ Added@adonisjs/core@2.10.4(transitive)
+ Added@adonisjs/encryption@1.0.4(transitive)
+ Added@adonisjs/env@1.0.18(transitive)
+ Added@adonisjs/events@1.0.10(transitive)
+ Added@adonisjs/fold@6.4.1(transitive)
+ Added@adonisjs/hash@1.0.12(transitive)
+ Added@adonisjs/http-server@1.8.2(transitive)
+ Added@adonisjs/logger@1.2.0(transitive)
+ Added@adonisjs/profiler@2.0.0(transitive)
+ Added@adonisjs/validator@6.3.0(transitive)
+ Added@hapi/bourne@2.1.0(transitive)
+ Added@phc/format@0.5.0(transitive)
+ Added@poppinss/colors@2.1.5(transitive)
+ Added@poppinss/cookie@1.0.8(transitive)
+ Added@poppinss/fancy-logs@1.3.9(transitive)
+ Added@poppinss/manager@2.1.8(transitive)
+ Added@poppinss/prompts@1.2.3(transitive)
+ Added@poppinss/utils@2.5.10(transitive)
+ Added@tokenizer/token@0.1.10.3.0(transitive)
+ Added@types/events@3.0.3(transitive)
+ Added@types/find-package-json@1.2.6(transitive)
+ Added@types/luxon@1.27.1(transitive)
+ Added@types/pino@5.20.0(transitive)
+ Added@types/proxy-addr@2.0.3(transitive)
+ Added@types/validator@13.12.2(transitive)
+ Addedabstract-logging@2.0.1(transitive)
+ Addedaccepts@1.3.8(transitive)
+ Addedansi-colors@4.1.3(transitive)
+ Addedansi-regex@3.0.15.0.1(transitive)
+ Addedat-least-node@1.0.0(transitive)
+ Addedatomic-sleep@1.0.0(transitive)
+ Addedbuffer-alloc@1.2.0(transitive)
+ Addedbuffer-alloc-unsafe@1.1.0(transitive)
+ Addedbuffer-fill@1.0.0(transitive)
+ Addedbytes@3.1.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcli-table3@0.5.1(transitive)
+ Addedclone-deep@4.0.1(transitive)
+ Addedco-compose@5.1.5(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedcolors@1.4.0(transitive)
+ Addedcontent-disposition@0.5.4(transitive)
+ Addedcookie@0.4.2(transitive)
+ Addedcookie-signature@1.2.2(transitive)
+ Addedcuid@2.1.8(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddedent@0.7.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddepd@1.1.22.0.0(transitive)
+ Addeddestroy@1.2.0(transitive)
+ Addeddot-case@3.0.4(transitive)
+ Addeddotenv@8.6.0(transitive)
+ Addedee-first@1.1.1(transitive)
+ Addedemittery@0.6.0(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedencodeurl@1.0.22.0.0(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedendent@1.4.1(transitive)
+ Addedenquirer@2.4.1(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedescape-html@1.0.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedetag@1.8.1(transitive)
+ Addedfast-json-parse@1.0.3(transitive)
+ Addedfast-redact@3.5.0(transitive)
+ Addedfast-safe-stringify@2.1.1(transitive)
+ Addedfigures@3.2.0(transitive)
+ Addedfile-type@14.7.1(transitive)
+ Addedfind-package-json@1.2.0(transitive)
+ Addedflatstr@1.0.12(transitive)
+ Addedforwarded@0.2.0(transitive)
+ Addedfresh@0.5.2(transitive)
+ Addedfs-extra@8.1.09.1.0(transitive)
+ Addedfs-readdir-recursive@1.1.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgetopts@2.3.0(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhaye@2.0.2(transitive)
+ Addedhttp-errors@1.8.12.0.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedipaddr.js@1.9.1(transitive)
+ Addedis-fullwidth-code-point@2.0.03.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedjest-worker@25.5.0(transitive)
+ Addedjsonfile@4.0.06.1.0(transitive)
+ Addedkind-of@6.0.3(transitive)
+ Addedkleur@4.1.5(transitive)
+ Addedklona@2.0.6(transitive)
+ Addedleven@3.1.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.get@4.4.2(transitive)
+ Addedlodash.set@4.3.2(transitive)
+ Addedlower-case@2.0.2(transitive)
+ Addedluxon@1.28.1(transitive)
+ Addedmacroable@4.0.4(transitive)
+ Addedmedia-typer@0.3.01.1.0(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.0.0(transitive)
+ Addedmultiparty@4.2.3(transitive)
+ Addedmustache@4.2.0(transitive)
+ Addednegotiator@0.6.3(transitive)
+ Addedno-case@3.0.4(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedobjectorarray@1.0.5(transitive)
+ Addedon-finished@2.4.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedparseurl@1.3.3(transitive)
+ Addedpeek-readable@4.1.0(transitive)
+ Addedpino@6.14.0(transitive)
+ Addedpino-std-serializers@3.2.0(transitive)
+ Addedpluralize@8.0.0(transitive)
+ Addedprocess-warning@1.0.0(transitive)
+ Addedproxy-addr@2.0.7(transitive)
+ Addedqs@6.13.1(transitive)
+ Addedquick-format-unescaped@4.0.4(transitive)
+ Addedquick-lru@5.1.1(transitive)
+ Addedrandom-bytes@1.0.0(transitive)
+ Addedrandombytes@2.0.3(transitive)
+ Addedrandomstring@1.3.0(transitive)
+ Addedrange-parser@1.2.1(transitive)
+ Addedreadable-web-to-node-stream@2.0.0(transitive)
+ Addedresolve-from@5.0.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedscmp@2.0.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedsend@0.19.0(transitive)
+ Addedserve-static@1.16.2(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedshallow-clone@3.0.1(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedsimple-encryptor@3.0.0(transitive)
+ Addedslash@3.0.0(transitive)
+ Addedsnake-case@3.0.4(transitive)
+ Addedsonic-boom@1.4.1(transitive)
+ Addedstatuses@1.5.02.0.1(transitive)
+ Addedstring-width@2.1.14.2.3(transitive)
+ Addedstrip-ansi@4.0.06.0.1(transitive)
+ Addedstrtok3@6.3.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedtoidentifier@1.0.1(transitive)
+ Addedtoken-types@2.1.1(transitive)
+ Addedts-essentials@6.0.7(transitive)
+ Addedtslib@2.8.1(transitive)
+ Addedtype-is@1.6.18(transitive)
+ Addedtypedarray-to-buffer@3.1.5(transitive)
+ Addedtypescript@5.7.2(transitive)
+ Addeduid-safe@2.1.5(transitive)
+ Addeduniversalify@0.1.22.0.1(transitive)
+ Addeduuid@7.0.3(transitive)
+ Addedvalidator@13.12.0(transitive)
+ Addedvary@1.1.2(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removed@poppinss/utils@1.0.9(transitive)
Updated@poppinss/utils@^2.0.0
Updated@types/ioredis@^4.0.17
Updatedioredis@^4.14.0