using CSRedis;
using dodohold.core;
using MySql.Data.MySqlClient;
using System.Data;


namespace molilian.core
{
    public partial class CenterHub
    {
        private static CSRedisClient _redis;
        private static bool _is_center = true;
        private static string _centerDB;
        public static bool IsCenter { get => _is_center; }
        static CenterHub()
        {
            string centerRedis = Environment.GetEnvironmentVariable("CenterRedis");
            string centerDB = Environment.GetEnvironmentVariable("CenterDB");
            if (string.IsNullOrEmpty(centerRedis))
            {
                _is_center = true;
                _redis = RedisHelper.Instance;
            }
            else
            {
                _is_center = false;
                _redis = RedisClientManager.GetRedisClient(centerRedis);
            }
        }

        public static CSRedisClient Redis => _redis;

        public static IDbConnection GetOpenConnection()
        {
            if (_is_center)
            {
                return DBContext.GetOpenConnection();
            }
            return DBContext.GetOpenConnection("CenterDB");
        }
    }
}

