Esempio n. 1
0
        public Task <Dictionary <string, DateTime> > GetAllAsync()
        {
            var       db        = _redis.GetDatabase();
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            return(db.HashGetAllAsync(_redisKeyClientActiveOnById).ContinueWith(t => {
                stopwatch.Stop();
                string text = $"{nameof(ClientActiveOnRedis)}的redis方法HashGetAllAsync耗时 {stopwatch.GetElapsedSeconds().ToString("f2")} 秒";
                NTMinerConsole.UserInfo(text);
                stopwatch.Restart();
                Dictionary <string, DateTime> dic = new Dictionary <string, DateTime>();
                foreach (var item in t.Result)
                {
                    if (item.Value.HasValue)
                    {
                        // 为了在redis-cli的易读性而存字符串
                        if (!DateTime.TryParse(item.Value, out DateTime activeOn))
                        {
                            activeOn = DateTime.MinValue;
                        }
                        dic.Add(item.Name, activeOn);
                    }
                }
                stopwatch.Stop();
                NTMinerConsole.UserInfo($"装配ClientActiveOn字典耗时 {stopwatch.GetElapsedSeconds().ToString("f2")} 秒");
                return dic;
            }));
        }
Esempio n. 2
0
        public Task <List <MinerData> > GetAllAsync()
        {
            var       db        = _redis.GetDatabase();
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            return(db.HashGetAllAsync(_redisKeyMinerById).ContinueWith(t => {
                stopwatch.Stop();
                string text = $"{nameof(ReadOnlyMinerDataRedis)}的redis方法HashGetAllAsync耗时 {stopwatch.GetElapsedSeconds().ToString("f2")} 秒";
                NTMinerConsole.UserInfo(text);
                stopwatch.Restart();
                List <MinerData> list = new List <MinerData>();
                foreach (var item in t.Result)
                {
                    if (item.Value.HasValue)
                    {
                        MinerData data = VirtualRoot.JsonSerializer.Deserialize <MinerData>(item.Value);
                        if (data != null)
                        {
                            list.Add(data);
                        }
                    }
                }
                stopwatch.Stop();
                NTMinerConsole.UserInfo($"反序列化和装配MinerData列表耗时 {stopwatch.GetElapsedSeconds().ToString("f2")} 秒");
                return list;
            }));
        }
Esempio n. 3
0
        public Task <Dictionary <Guid, SpeedData> > GetAllAsync()
        {
            var       db        = _redis.GetDatabase();
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            return(db.HashGetAllAsync(_redisKeySpeedDataByClientId).ContinueWith(t => {
                stopwatch.Stop();
                string text = $"{nameof(SpeedDataRedis)}的redis方法HashGetAllAsync耗时 {stopwatch.GetElapsedSeconds().ToString("f2")} 秒";
                NTMinerConsole.UserInfo(text);
                stopwatch.Restart();
                Dictionary <Guid, SpeedData> dic = new Dictionary <Guid, SpeedData>();
                foreach (var item in t.Result)
                {
                    if (item.Value.HasValue)
                    {
                        SpeedData data = VirtualRoot.JsonSerializer.Deserialize <SpeedData>(item.Value);
                        if (data != null)
                        {
                            dic.Add(data.ClientId, data);
                        }
                    }
                }
                stopwatch.Stop();
                NTMinerConsole.UserInfo($"反序列化和装配SpeedData列表耗时 {stopwatch.GetElapsedSeconds().ToString("f2")} 秒");
                return dic;
            }));
        }
        public Task <ClientTestIdData> GetAsync()
        {
            var db = _redis.GetDatabase();

            return(db.StringGetAsync(_redisKeyClientTestId).ContinueWith(t => {
                string json = t.Result;
                if (!string.IsNullOrEmpty(json))
                {
                    return VirtualRoot.JsonSerializer.Deserialize <ClientTestIdData>(json);
                }
                return null;
            }));
        }
Esempio n. 5
0
        public Task <CalcConfigData[]> GetAllAsync()
        {
            var db = _redis.GetDatabase();

            return(db.HashGetAllAsync(_redisKeyCalcConfigs).ContinueWith(t => {
                List <CalcConfigData> list = new List <CalcConfigData>();
                foreach (var item in t.Result)
                {
                    if (item.Value.HasValue)
                    {
                        CalcConfigData data = VirtualRoot.JsonSerializer.Deserialize <CalcConfigData>(item.Value);
                        if (data != null)
                        {
                            list.Add(data);
                        }
                    }
                }
                return list.ToArray();
            }));
        }
        public Task <Dictionary <string, DateTime> > GetAllAddress()
        {
            var db = _redis.GetDatabase();

            return(db.HashGetAllAsync(_redisKeyWsServerNodeAddress).ContinueWith(t => {
                Dictionary <string, DateTime> dic = new Dictionary <string, DateTime>();
                foreach (var item in t.Result)
                {
                    if (item.Value.HasValue && DateTime.TryParse(item.Value, out DateTime activeOn))
                    {
                        dic.Add(item.Name, activeOn);
                    }
                }
                return dic;
            }));
        }