Upgrade redis client to 4.x

This commit is contained in:
斟酌 鵬兄 2022-04-06 15:47:51 +09:00
parent df548739da
commit c3ccc680d9
2 changed files with 17 additions and 17 deletions

View File

@ -10,12 +10,6 @@ var Client = Redis.createClient({
, "url": `redis://${SessConf.config.host}:${SessConf.config.port}/${SessConf.config.database}`
});
Client.addListener( "error", ( e ) => { throw e; } );
Client.select( SessConf.config.database, function( err, message )
{
if( err ) throw err;
Dragonfly.Info( "[Session] Database connected. Ready." );
});
Client.connect();
module.exports = Client;

View File

@ -44,9 +44,13 @@ class Session extends EventEmitter
{
if( err ) throw err;
if( _self.exists = !!obj )
if( _self.exists = !!obj.length )
{
_self.__sess = obj;
_self.__sess = {};
for( var i = 0, l = obj.length; i < l; i += 2 )
{
_self.__sess[obj[i]] = obj[ i + 1 ];
}
}
// Auto reset the session id if no match
else if( !noIdReset )
@ -91,10 +95,17 @@ class Session extends EventEmitter
Client.DEL( this.id, handler || this.__emitOk );
}
set( name, val )
set( dict, handler )
{
this.__sess[ name ] = val;
Client.HSET( this.id, name, val, this.__emitOk );
var chain = Client.multi();
for( let k in dict )
{
var v = dict[k];
this.__sess[ k ] = v;
chain = chain.HSET( this.id, k, v );
}
chain.exec( handler || this.__emitOk );
}
get( name )
@ -140,11 +151,6 @@ class Session extends EventEmitter
.EXPIRE( this.id, ttl, this.__emitOk )
.exec( this.__emitOk );
}
get busy()
{
return 0 < ( Client.command_queue.length + Client.offline_queue.length );
}
}
Session.SessionEventArgs = SessionEventArgs;