import Redis from 'ioredis';

if(global.redis === undefined)
{
	//console.log("REDIS NOT SET", process.env.REDIS_URL, "\n\n\n");

	global.redis = new Redis(process.env.REDIS_URL, { connectionName: process.env.REDIS_CLIENT_NAME });
}

export default class RedisClient 
{
	constructor()
	{
		//console.log("REDIS CLIENT", "constructor");

	}

	static async get(key)
	{
		return await global.redis.get(key);
	}

	static async set(key, value, ex, lifetime)
	{
		//console.log("REDIS CLIENT", "set", { key, value, ex, lifetime });

		if(lifetime !== undefined)
		{
			return await global.redis.set(key, value, ex, lifetime);
		}
		else if (ex !== undefined)
		{
			return await global.redis.set(key, value, ex);
		}
		else
		{
			return await global.redis.set(key, value);
		}
	}

	static async del(key)
	{
		return await global.redis.del(key);
	}


	static async keys(keys)
	{
		return await global.redis.keys(keys);
	}
	//cons
}