本文整理匯總了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);
}
}