2016-05-31 09:55:08 +00:00
|
|
|
const cl = global.botanLoader;
|
|
|
|
const Dragonfly = global.Dragonfly;
|
|
|
|
|
|
|
|
const Redis = require( "redis" );
|
|
|
|
|
2022-04-03 12:55:43 +00:00
|
|
|
const SessConf = cl.load( "config.all" ).sx.modular.session;
|
2016-05-31 09:55:08 +00:00
|
|
|
|
2023-01-31 22:21:52 +00:00
|
|
|
class ClientCompat
|
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
this.client = Redis.createClient({
|
|
|
|
"url": `redis://${SessConf.config.host}:${SessConf.config.port}/${SessConf.config.database}`
|
|
|
|
});
|
|
|
|
}
|
2016-05-31 09:55:08 +00:00
|
|
|
|
2023-01-31 22:21:52 +00:00
|
|
|
async _connect()
|
|
|
|
{
|
|
|
|
if( this.client.isReady )
|
|
|
|
return;
|
|
|
|
await this.client.connect();
|
|
|
|
}
|
2016-05-31 09:55:08 +00:00
|
|
|
|
2023-01-31 22:21:52 +00:00
|
|
|
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 )
|
|
|
|
{
|
|
|
|
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();
|