public List<string> Get(string prefix)
 {
     List<string> ret = new List<string>();
     BookSleeve.RedisConnection connection = new BookSleeve.RedisConnection(".redis.cache.windows.net",
         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)
 {
     List<string> ret = new List<string>();
     BookSleeve.RedisConnection connection = new BookSleeve.RedisConnection(ConfigurationManager.AppSettings["mCacheUrl"],
         password: ConfigurationManager.AppSettings["mCachePassword"]);
     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>();
     BookSleeve.RedisConnection connection = new BookSleeve.RedisConnection(".redis.cache.windows.net",
         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 List<string> Get(string prefix, string category)
 {
     List<string> ret = new List<string>();
     BookSleeve.RedisConnection connection = new BookSleeve.RedisConnection(ConfigurationManager.AppSettings["mCacheUrl2"],
         password: ConfigurationManager.AppSettings["mCachePassword2"]);
     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;
 }
Exemplo n.º 5
0
        static void primeProuctCache()
        {
            if (!confirmOperation("YOUR CACHE WILL BE FLUSHED! ALL EXISTING INDEXES WILL BE REPLACED! Are you sure?"))
                return;

            CloudStorageAccount account = CloudStorageAccount.Parse(mStorageConnectionString);
            var client = account.CreateCloudTableClient();
            var table = client.GetTableReference("products");
            var query = from c in table.CreateQuery<Product>()
                        select c;

            var connection = new BookSleeve.RedisConnection(mCacheUrl2, allowAdmin: true,
                password: mCachePassword2);
            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);
                Console.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);
        }
 private List<string> getTopKeys(string category, int top)
 {
     List<string> ret = new List<string>();
     BookSleeve.RedisConnection connection = new BookSleeve.RedisConnection(redisUrl2,
         password: redisPassword2);
     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;
 }
 private List<Product> getProducts(string category, double start, double end)
 {
     List<Product> ret = new List<Product>();
     BookSleeve.RedisConnection connection = new BookSleeve.RedisConnection(redisUrl2,
         password: redisPassword2);
     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)
             ret.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 ret;
 }