public List<GroupedError> Get() { var client = new RedisClient(); client.ChangeDb(2); const string keyPattern = "elmah-error:*"; var errorLogKeys = client.SearchKeys(keyPattern); IEnumerable<ErrorModel> allError = client.GetAll<ErrorModel>(errorLogKeys).Values; return ErrorLogAnalyzer(allError); }
public AutorService() { using (var redisClient = new RedisClient("dockerdotnetencamina.westus.cloudapp.azure.com", 6379)) { _collection = redisClient.GetAll<Autor>().OrderBy(x=>x.Name); } }
public IList<Trip> GetAllTrips() { try { using (_client = new RedisClient()) { return _client.GetAll<Trip>(); } } catch(Exception ex) { _logger.LogError("", ex); return null; } }
public ActionResult Import() { var importService = new ImportService(); IEnumerable<Article> list = new List<Article>(); //var redisUrl = ConfigurationManager.AppSettings.Get("REDISTOGO_URL"); var connectionUri = "ec2-54-247-0-119.eu-west-1.compute.amazonaws.com";//new Uri("redis://*****:*****@barb.redistogo.com:9371/"); using (var redisClient = new RedisClient(connectionUri, 6379)) { if(redisClient.As<Article>().GetAll().Count != 0) redisClient.As<Article>().DeleteAll(); var importedArticles = importService.ImportArticlesAsync(redisClient); redisClient.StoreAll(importedArticles); list = redisClient.GetAll<Article>(); } return View(list.Take(1)); //return View("Gizmos", await importService.ImportArticlesAsync()); }
private List<Entity.BCTC> GetTopBCTC(string symbol, string type, int fromYear, int fromQuarter, int count) { var redis = new RedisClient(ConfigRedis.Host, ConfigRedis.Port); var keys = redis.SearchKeys(string.Format(RedisKey.BCTCKey, symbol.Trim().ToUpper(), type.Trim().ToUpper(), fromQuarter > 0 ? 1 : 0, "*", "*")); keys.Sort(); keys.Reverse(); var i = 0; while (i < keys.Count) { if (i >= count) { keys.RemoveAt(i); continue; } var tmp = keys[i].Substring(keys[i].Length - 6); var year = int.Parse(tmp.Substring(0, 4)); var quarter = int.Parse(tmp.Substring(5)); if (year > fromYear) { keys.RemoveAt(i); continue; } if (year == fromYear && quarter > fromQuarter) { keys.RemoveAt(i); continue; } i++; } return keys.Count == 0 ? new List<Entity.BCTC>() : redis.GetAll<Entity.BCTC>(keys).Values.ToList(); }
public static void Main() { try { var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var file = Path.Combine(Path.Combine(path, "cmd"), "redis-server.exe"); if (File.Exists(file)) { var redis = new ProcessStartInfo() { FileName = file }; using (var server = Process.Start(redis)) { if (server.Responding) { using (var client = new RedisClient()) { client.FlushAll(); CatalogInitializer.Configure(); // Create "[CREATE] StoreAll".ToConsoleInfo(); client.StoreAll<Book>(CatalogInitializer.Seed()); // Read "[READ] GetAll".ToConsoleInfo(); var catalog = client.GetAll<Book>().ToList(); catalog.ForEach(retrieved => retrieved.ToJson<Book>().ToConsole()); var isbn = "9780596800956"; string.Format("[READ] GetById (Isbn = {0})", isbn).ToConsoleInfo(); client.GetById<Book>(isbn).ToJson<Book>().ToConsole(); // Update "[UPDATE] (InStock = false)".ToConsoleInfo(); var book = client.GetById<Book>(isbn); book.InStock = false; client.Store<Book>(book); client.GetById<Book>(isbn).ToJson<Book>().ToConsole(); // Delete string.Format("[DELETE] DeleteById (Isbn = {0})", isbn).ToConsoleInfo(); client.DeleteById<Book>(isbn); client.GetById<Book>(isbn).ToJson<Book>().ToConsole(); } } } } } catch (Exception exception) { exception.ToString().ToConsole(); } finally { "Press any key to continue . . .".ToConsole(); Console.ReadKey(true); } }
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); } }
private void button6_Click(object sender, EventArgs e) { var symbol = "SSI"; var redis = new RedisClient(ConfigRedis.Host, ConfigRedis.Port); var ret = new List<StockNews>(); var key = string.Format(RedisKey.KeyCompanyNewsByStock, symbol, 0); var ls = redis.ContainsKey(key) ? redis.Get<List<string>>(key) : new List<string>(); ls = ls.FindAll(sn => double.Parse(Utility.getDateTime(sn)) <= double.Parse(DateTime.Now.ToString("yyyyMMddHHmm"))); var lspaging = Utility.GetPaging<string>(ls, 0 + 1, 10); for (int i = 0; i < lspaging.Count; i++) { lspaging[i] = Utility.getNewsID(lspaging[i]); } var tmp = redis.GetAll<StockNews>(lspaging); foreach (StockNews sn in tmp.Values) { ret.Add(sn); } }
public void Can_replicate_to_redis_when_document_is_updated_using_pocoTypeMode() { CleanOldRedisData(); using (var session = documentStore.OpenSession()) { session.Advanced.DatabaseCommands.Delete("Raven/IndexReplicationToRedis/Questions/Votes", null); session.Store(new IndexReplicationToRedisDestination { Id = "Raven/IndexReplicationToRedis/Questions/Votes" , Server = RedisServerUri , RedisSaveMode = IndexReplicationToRedisMode.PocoType, PocoTypeAssemblyQualifiedName = typeof(QuestionSummary).AssemblyQualifiedName }); session.SaveChanges(); } using (var session = documentStore.OpenSession()) { var q = new Question { Id = "questions/1", Title = "How to replicate to Redis?", QuestionDate = DateTime.Now.Date, Votes = new[] { new Vote{ Up = true, Comment = "Good!", Points = 1.2}, new Vote{ Up = false, Comment = "Nah!" , Points = 1.3}, new Vote{ Up = true, Comment = "Nice..." , Points = 1.4}, } }; session.Store(q); session.SaveChanges(); } using (var session = documentStore.OpenSession()) { session.Advanced.LuceneQuery<Question>("Questions/Votes") .WaitForNonStaleResults() .SelectFields<QuestionSummary>("__document_id", "Title", "UpVotes", "DownVotes", "QuestionDate", "SumPoints") .ToList(); } using (var session = documentStore.OpenSession()) { var q = new Question { Id = "questions/1", Title = "How to replicate to Redis?", QuestionDate = DateTime.Now.Date, Votes = new[] { new Vote{ Up = true, Comment = "Good!", Points = 1.2}, new Vote{ Up = false, Comment = "Nah!" , Points = 1.3}, new Vote{ Up = true, Comment = "Nice..." , Points = 1.4}, new Vote{ Up = false, Comment = "No!", Points = 1.5} } }; session.Store(q); session.SaveChanges(); } using (var session = documentStore.OpenSession()) { session.Advanced.LuceneQuery<Question>("Questions/Votes") .WaitForNonStaleResults() .SelectFields<QuestionSummary>("__document_id", "Title", "UpVotes", "DownVotes", "QuestionDate", "SumPoints") .ToList(); } using (var redisClient = new RedisClient(RedisServerUri)) { var questions = redisClient.GetAll<QuestionSummary>(); Assert.True(questions.Count > 0); var firstQuestion = questions.First(); Assert.Equal("questions/1", firstQuestion.Id); Assert.Equal("How to replicate to Redis?", firstQuestion.Title); Assert.Equal(2, firstQuestion.UpVotes); Assert.Equal(2, firstQuestion.DownVotes); Assert.Equal(DateTime.Now.Date, firstQuestion.QuestionDate); } }