const cl = global.botanLoader; const Dragonfly = global.Dragonfly; const Redis = require( "redis" ); const SessConf = cl.load( "config.all" ).sx.modular.session; class ClientCompat { constructor() { this.client = Redis.createClient({ "url": `redis://${SessConf.config.host}:${SessConf.config.port}/${SessConf.config.database}` }); } async _connect() { if( this.client.isReady ) return; await this.client.connect(); } async GET( key, handler ) { try { await this._connect(); handler( await this.client.GET( key ) ); } catch( error ) { handler( undefined, error ); } } async HGET( key, field, handler ) { try { await this._connect(); handler( await this.client.HGET( key, field ) ); } catch( error ) { handler( undefined, error ); } } async HGETALL( key, handler ) { try { await this._connect(); handler( await this.client.HGETALL( key ) ); } catch( error ) { handler( undefined, error ); } } async DEL( key, handler ) { if( !handler ) throw new Error( "handler cannot be undefined" ); try { await this._connect(); handler( await this.client.DEL( key ) ); } catch( error ) { handler( undefined, error ); } } async HDEL( key, field, handler ) { try { await this._connect(); handler( await this.client.HDEL( key, field ) ); } catch( error ) { handler( undefined, error ); } } async TTL( key, handler ) { try { await this._connect(); handler( await this.client.TTL( key ) ); } catch( error ) { handler( undefined, error ); } } async compatExec( multi, handler ) { try { await this._connect(); handler( await multi.exec() ); } catch( error ) { handler( undefined, error ); } } multi() { return this.client.multi(); } } module.exports = new ClientCompat();