当前位置: 首页>>代码示例>>C#>>正文


C# RedisClient.SetAll方法代码示例

本文整理汇总了C#中ServiceStack.Redis.RedisClient.SetAll方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.SetAll方法的具体用法?C# RedisClient.SetAll怎么用?C# RedisClient.SetAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ServiceStack.Redis.RedisClient的用法示例。


在下文中一共展示了RedisClient.SetAll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteTask

        public void ExecuteTask()
        {
            try
            {
                var isTrading = false;
                var bfirstTime = true;
                var isBeginTrading = false;
                var isEndTrading = false;
                var ss = new List<StockCompact>();
                var keys = new List<string>();
                var priceKeys = new List<string>();
                var syms = new List<string>();
                var objs = new Dictionary<string, SessionPriceData>();
                var redis = new RedisClient(ConfigRedis.Host, ConfigRedis.Port);
                var redisPrice = new RedisClient(ConfigRedis.PriceHost, ConfigRedis.PricePort);
                while (ServiceStarted)
                {
                    try
                    {
                        var b = Utils.InTradingTime(TradeCenterId);
                        isBeginTrading = (!isTrading && b);
                        isEndTrading = (isTrading && !b);
                        isTrading = b;
                        if (!bfirstTime) Thread.Sleep(isTrading ? tradeInterval : noTradeInterval);
                        if (bfirstTime || isBeginTrading)
                        {
                            var key = string.Format(RedisKey.KeyStockListByCenter, TradeCenterId);
                            ss = redis.Get<List<StockCompact>>(key);
                            keys = new List<string>();
                            syms = new List<string>();
                            objs = new Dictionary<string, SessionPriceData>();
                            foreach (var s in ss)
                            {
                                keys.Add(string.Format(RedisKey.RealtimeSessionPrice, s.Symbol));
                                priceKeys.Add(string.Format(RedisKey.PriceKey, s.Symbol));
                                syms.Add(s.Symbol);
                                objs.Add(string.Format(RedisKey.RealtimeSessionPrice, s.Symbol), new SessionPriceData() { Symbol = s.Symbol, Price = -1, TotalValue = 0, TotalVolume = 0, TradeDate = DateTime.Now, Volume = 0 });
                            }
                            //init objects
                            if (isBeginTrading)
                            {
                                redis.SetAll(objs);
                            }
                            else
                            {
                                objs = (Dictionary<string, SessionPriceData>)redis.GetAll<SessionPriceData>(keys);
                            }
                        }
                        bfirstTime = false;
                        if (isTrading)
                        {
                            //detect change
                            var prices = redisPrice.GetAll<StockPrice>(priceKeys);
                            foreach (var sym in syms)
                            {
                                var price = prices[string.Format(RedisKey.PriceKey, sym)];
                                var obj = objs[string.Format(RedisKey.RealtimeSessionPrice, sym)];
                                if (price == null || obj == null) continue;
                                if (obj.Price != price.Price || obj.TotalVolume != price.Volume)
                                {
                                    var vol = price.Volume - obj.TotalVolume;
                                    //trade time --> save
                                    if (obj.Price > -1) //don't save the initial value
                                    {
                                        var key = string.Format(RedisKey.SessionPrice, obj.Symbol, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"));
                                        var o = new SessionPriceData() { Symbol = obj.Symbol, Price = price.Price, TotalValue = price.Value, TotalVolume = price.Volume, TradeDate = DateTime.Now, Volume = vol };
                                        if (redis.ContainsKey(key))
                                            redis.Set(key, o);
                                        else
                                            redis.Add(key, o);
                                    }
                                    //save realtime object
                                    obj.Price = price.Price;
                                    obj.Volume = vol;
                                    obj.TotalVolume = price.Volume;
                                    obj.TotalValue = price.Value;
                                    objs[string.Format(RedisKey.RealtimeSessionPrice, sym)] = obj;
                                }
                            }
                            redis.SetAll(objs);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.WriteEntry(ex.ToString(), EventLogEntryType.Error);
                    }

                }
            }
            catch (Exception ex)
            {
                log.WriteEntry(ex.ToString(), EventLogEntryType.Error);
            }
        }
开发者ID:giangcoffee,项目名称:cafef.redis,代码行数:94,代码来源:PriceData.cs


注:本文中的ServiceStack.Redis.RedisClient.SetAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。