/*
 * @Descripttion: 
 * @version: 0.0.0
 * @Author: genglw
 * @Date: 2022-02-12 20:34:11
 * @LastEditors: genglw
 * @LastEditTime: 2022-02-15 11:09:45
 */
var redis = require('redis');

exports = module.exports = function (logger, settings) {

	async function set(key, value) {
		const client = redis.createClient({
			url: `redis://${settings.redis.host}:${settings.redis.port}`,
			password: settings.redis.pass,
		});

		client.on('error', (err) => logger.info('Redis Client Error', err));

		await client.connect();
		await client.set(key, value);
		await client.quit();
	}

	async function get(key) {
		const client = redis.createClient({
			url: `redis://${settings.redis.host}:${settings.redis.port}`,
			password: settings.redis.pass,
		});

		client.on('error', (err) => logger.info('Redis Client Error', err));

		await client.connect();
		const value = await client.get(key);
		await client.quit();

		return value;
	}

	return {
		set: set,
		get: get,
	};
};




exports['@singleton'] = true;
exports['@require'] = ['igloo/logger', 'igloo/settings'];