Allow handler to be undefined
This commit is contained in:
parent
b2b6bee892
commit
e8778acf66
@ -14,6 +14,8 @@ class ClientCompat
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_nop() { }
|
||||||
|
|
||||||
async _connect()
|
async _connect()
|
||||||
{
|
{
|
||||||
if( this.client.isReady )
|
if( this.client.isReady )
|
||||||
@ -23,6 +25,7 @@ class ClientCompat
|
|||||||
|
|
||||||
async GET( key, handler )
|
async GET( key, handler )
|
||||||
{
|
{
|
||||||
|
handler = handler || this._nop;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await this._connect();
|
await this._connect();
|
||||||
@ -36,6 +39,7 @@ class ClientCompat
|
|||||||
|
|
||||||
async HGET( key, field, handler )
|
async HGET( key, field, handler )
|
||||||
{
|
{
|
||||||
|
handler = handler || this._nop;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await this._connect();
|
await this._connect();
|
||||||
@ -49,6 +53,7 @@ class ClientCompat
|
|||||||
|
|
||||||
async HGETALL( key, handler )
|
async HGETALL( key, handler )
|
||||||
{
|
{
|
||||||
|
handler = handler || this._nop;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await this._connect();
|
await this._connect();
|
||||||
@ -62,9 +67,7 @@ class ClientCompat
|
|||||||
|
|
||||||
async DEL( key, handler )
|
async DEL( key, handler )
|
||||||
{
|
{
|
||||||
if( !handler )
|
handler = handler || this._nop;
|
||||||
throw new Error( "handler cannot be undefined" );
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await this._connect();
|
await this._connect();
|
||||||
@ -78,6 +81,7 @@ class ClientCompat
|
|||||||
|
|
||||||
async HDEL( key, field, handler )
|
async HDEL( key, field, handler )
|
||||||
{
|
{
|
||||||
|
handler = handler || this._nop;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await this._connect();
|
await this._connect();
|
||||||
@ -91,6 +95,7 @@ class ClientCompat
|
|||||||
|
|
||||||
async TTL( key, handler )
|
async TTL( key, handler )
|
||||||
{
|
{
|
||||||
|
handler = handler || this._nop;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await this._connect();
|
await this._connect();
|
||||||
@ -104,6 +109,7 @@ class ClientCompat
|
|||||||
|
|
||||||
async compatExec( multi, handler )
|
async compatExec( multi, handler )
|
||||||
{
|
{
|
||||||
|
handler = handler || this._nop;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await this._connect();
|
await this._connect();
|
||||||
|
@ -62,8 +62,8 @@ class Session extends EventEmitter
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
this.__sess = {};
|
this.__sess = {};
|
||||||
this.__emitOk = ( e, m ) => {
|
this.__emitOk = ( m, err ) => {
|
||||||
_self.__emit( e, "set", new SessionEventArgs( m ) );
|
_self.__emit( err, "set", new SessionEventArgs( m ) );
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ class Session extends EventEmitter
|
|||||||
.HSET( this.id, "spawn", new Date().getTime() )
|
.HSET( this.id, "spawn", new Date().getTime() )
|
||||||
.HSET( this.id, "lifespan", ttl )
|
.HSET( this.id, "lifespan", ttl )
|
||||||
.EXPIRE( this.id, ttl )
|
.EXPIRE( this.id, ttl )
|
||||||
, ( data, err ) => ( handler || this.__emitOk)( err, data )
|
, handler || this.__emitOk
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ class Session extends EventEmitter
|
|||||||
var _self = this;
|
var _self = this;
|
||||||
Client.HGET(
|
Client.HGET(
|
||||||
this.id, name
|
this.id, name
|
||||||
, function( err, rep )
|
, function( rep, err )
|
||||||
{
|
{
|
||||||
_self.__emitOk( err );
|
_self.__emitOk( err );
|
||||||
_self.__sess[ name ] = rep;
|
_self.__sess[ name ] = rep;
|
||||||
|
Loading…
Reference in New Issue
Block a user