public void Setup()
 {
     var connection = new RedisConnection("127.0.0.1", allowAdmin: true);
     connection.Open();
     connection.Server.FlushDb(0);
     connection.Close(false);
 }
		public List<string> Get(string prefix)
		{
			List<string> ret = new List<string>();
			RedisConnection connection = new RedisConnection(
				host: DemoSettings.CustomerRedisCache.Url, 
				password: DemoSettings.CustomerRedisCache.Password);
			connection.Open();
			var list = connection.Wait(connection.Keys.Find(0, "cust:" + prefix.Replace(' ', ':') + "*"));
			for (int i = 0; i < Math.Min(5, list.Length); i++)
			{
				ret.Add(list[i].Substring(5).Replace(':', ' '));
			}
			connection.Close(false);
			return ret;
		}
		public List<string> Get(string prefix, string category)
		{
			List<string> ret = new List<string>();
			RedisConnection connection = new RedisConnection(
				host: DemoSettings.ProductsRedisCache.Url,
				password: DemoSettings.ProductsRedisCache.Password);
			connection.Open();
			var list = connection.Wait(connection.Keys.Find(0, "prod:" + category + ":" + prefix.Replace(' ', ':') + "*"));
			for (int i = 0; i < Math.Min(5, list.Length); i++)
			{
				string s = list[i].Substring(5);
				s = s.Substring(s.IndexOf(':') + 1);
				ret.Add(s.Replace(':', ' '));
			}
			connection.Close(false);
			return ret;
		}
        public static void Main(string[] args)
        {
            var time = new DateTime(2013, 11, 11, 10, 30, 0);
            var redis = new RedisConnection("localhost");
            redis.Wait(redis.Open());

            var activity = new RedisActivityMonitor(redis);

            // Normal activity.
            activity.Beacon("documents:1", time.AddSeconds(-15), 1, "John");
            activity.Beacon("documents:1", time, 2, "Sue");
            activity.Beacon("documents:1", time.AddSeconds(5), 3, "Mary");
            PrintAll(activity, "documents:1", time.AddSeconds(23));

            // Ignore duplicates.
            activity.Beacon("documents:2", time, 1, "John");
            activity.Beacon("documents:2", time.AddSeconds(5), 1, "John");
            PrintAll(activity, "documents:2", time.AddSeconds(7));

            redis.Close(abort: true);

            Console.Read();
        }
Example #5
0
		private List<string> getTopKeys(string category, int top)
		{
			List<string> ret = new List<string>();
			RedisConnection connection = new RedisConnection(DemoSettings.ProductsRedisCache.Url,
					password: DemoSettings.ProductsRedisCache.Password);
			connection.Open();
			var list = connection.SortedSets.Range(0, "rate:" + category, start: 0, stop: top, ascending: false).Result;
			foreach (var item in list)
				ret.Add(Encoding.ASCII.GetString(item.Key));
			connection.Close(false);
			return ret;
		}
Example #6
0
		private List<Product> getProducts(string category, double start, double end)
		{
			var products = new List<Product>();
			var connection = new RedisConnection(DemoSettings.ProductsRedisCache.Url,
					password: DemoSettings.ProductsRedisCache.Password);
			connection.Open();
			var list = connection.SortedSets.Range(0, "cat:" + category, min: start, max: end, ascending: false).Result;
			foreach (var item in list)
			{
				string[] parts = Encoding.ASCII.GetString(item.Key).Split(':');
				if (parts.Length == 5)
					products.Add(new Product
					{
						Category = parts[0],
						Name = parts[2],
						Price = (int)(double.Parse(parts[3]) * 100) / 100.0,
						Rate = int.Parse(parts[4])
					});
			}
			connection.Close(false);
			return products;
		}
Example #7
0
		private static void PrimeProuctCache(TextWriter log)
		{
			if (!ConfirmOperation("YOUR CACHE WILL BE FLUSHED! ALL EXISTING INDEXES WILL BE REPLACED! Are you sure?", log))
				return;

			var client = CloudStorageAccount.CreateCloudTableClient();
			var table = client.GetTableReference(DemoSettings.Storage.ProductsTableName);
			var query = from product in table.CreateQuery<Product>() select product;

			var connection = new RedisConnection(DemoSettings.ProductsRedisCache.Url, allowAdmin: true, password: DemoSettings.ProductsRedisCache.Password);
			connection.Open();
			connection.Server.FlushDb(0);
			foreach (var c in query)
			{
				string key = string.Format("{0}:{1}:{2}:{3}:{4}", c.PartitionKey, c.RowKey, c.Name, c.Price, c.Rate);
				log.WriteLine("{0}:{1}", key, c.Name);
				connection.SortedSets.Add(0, "cat:" + c.Category, key, c.Price);
				connection.SortedSets.Add(0, "rate:" + c.Category, key, c.Rate);
				connection.Strings.Set(0, "prod:" + c.Category + ":" + c.Name.Replace(' ', ':'), key);
			}
			connection.Close(false);
		}