diff --git a/redisclient.js b/redisclient.js index 3781668..6907ee9 100644 --- a/redisclient.js +++ b/redisclient.js @@ -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; diff --git a/session.js b/session.js index 885d0ec..08fd647 100644 --- a/session.js +++ b/session.js @@ -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;