Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                redisHost = ConfigurationManager.AppSettings["redisHost"];
                redisPort = int.Parse(ConfigurationManager.AppSettings["redisPort"]);
                redisPassword = ConfigurationManager.AppSettings["redisPassword"];

                if (!IsPostBack)
                {
                    RedisClient redisClient = new RedisClient(redisHost, redisPort) { Password = redisPassword };
                    using (var redisGuids = redisClient.GetTypedClient<Guids>())
                    {
                        redisGuids.Store(new Guids { Date = DateTime.Now, Value = Guid.NewGuid() });
                        var allValues = redisGuids.GetAll();
                        GridView1.DataSource = allValues;
                        GridView1.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new WebException(ex.ToString(), WebExceptionStatus.ConnectFailure);
            }
        }
Exemplo n.º 2
0
		/// <summary>
		/// Ctor. Obtains and stores a reference to a typed Redis client.
		/// </summary>
		public RedisQueueClient()
		{
			_client = new RedisClient(Settings.Default.RedisHost, Settings.Default.RedisPort);
			_taskMessageClient = _client.GetTypedClient<TaskMessage>();

			_log.Info("Connected to Redis.");
			_log.DebugFormat("Connection Properties: {0}:{1}",
				Settings.Default.RedisHost, Settings.Default.RedisPort);
		}
        private List<PlayEvent<StubModel>> GetChangesFor(string modelId)
        {
            using (var redisClient = new RedisClient())
            {
                var redis = redisClient.GetTypedClient<PlayEvent<StubModel>>();

                return redis.Lists["urn:changes:" + modelId].GetAll();
            }
        }
Exemplo n.º 4
0
        public static void StoreInHash(string key, string value)
        {
            using (IRedisClient client = new RedisClient())
            {
                var objClient = client.GetTypedClient<string>();

                var hash = objClient.GetHash<string>(keyPredicate + key.ToString());

                hash.Add(key, value);
            }
        }
        public JsonResult ClearAllChanges()
        {
            using (var redisClient = new RedisClient())
            {
                var redis = redisClient.GetTypedClient<StubAddedEvent>();

                redis.SetSequence(0);
                redis.FlushAll();
            }

            return this.Json("Changes cleared");
        }
Exemplo n.º 6
0
		public RedisQueueService(Uri baseUri, bool resume)
		{
			using (RedisClient redisClient = new RedisClient())
			{
				_redis = redisClient.GetTypedClient<Entry>();
				_queue = _redis.Lists[string.Format("barcodes:{0}:queue", baseUri)];
				if (!resume)
				{
					_queue.Clear();
				}
			}
		}
Exemplo n.º 7
0
		public RedisHistoryService(Uri baseUri, bool resume)
		{
			using (RedisClient redisClient = new RedisClient())
			{
				_redis = redisClient.GetTypedClient<string>();
				_history = _redis.Sets[string.Format("barcodes:{0}:history", baseUri)];
				if (!resume)
				{
					_history.Clear();
				}
			}
		}
Exemplo n.º 8
0
        public static string GetValue(string key)
        {
            string returnedValue;
            using (IRedisClient client = new RedisClient())
            {

                var objClient = client.GetTypedClient<string>();

                var hash = objClient.GetHash<string>(keyPredicate + key);
                returnedValue = hash[key];
            }

            return returnedValue;
        }
        public ViewResult Index()
        {
            var redis = new RedisClient();

            using (var redisStatus = redis.GetTypedClient<UserStatus>())
            {
                var allstatus = redisStatus.GetAll();

                var query = (from items in allstatus
                             select items).ToList();

                return View(query);
            }

        }
Exemplo n.º 10
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            string redisHost = ConfigurationManager.AppSettings["redisHost"];
            int redisPort = int.Parse(ConfigurationManager.AppSettings["redisPort"]);
            string redisPassword = ConfigurationManager.AppSettings["redisPassword"];

            RedisClient redisClient = new RedisClient(redisHost, redisPort) { Password = redisPassword };
            using (var redisGuids = redisClient.GetTypedClient<Guids>())
            {
                redisGuids.DeleteAll();
                var allValues = redisGuids.GetAll();
                GridView1.DataSource = allValues;
                GridView1.DataBind();
            }
        }
        public ActionResult Edit(int id)
        {
            var redis = new RedisClient();

            using (var redisstatus = redis.GetTypedClient<UserStatus>())
            {

                // Call all items then , select item using id of item
                // we don't know id of item stored 
                // in redis , so search is required.

                var item = redisstatus.GetAll().Where(i => i.id.Equals(id));
                return View(item.First());
            }

        }
Exemplo n.º 12
0
		public QueueClient(string host, int port, bool enableCaching)
		{
			RedisHost = host;
			RedisPort = port;

			GenericClient = new RedisClient(RedisHost, RedisPort);
			TypedClient = GenericClient.GetTypedClient<TaskMessage>();
			
			Log.Info("Connected to Redis.");
			Log.DebugFormat("Connection Properties: {0}:{1}", Settings.Default.RedisHost, Settings.Default.RedisPort);
			
			LocalCachingEnabled = enableCaching;
			if (LocalCachingEnabled)
			{
				Log.Info("Caching 's enabled. Cache location: " + Settings.Default.LocalCache);
				CheckCacheAndRetrieveState();
			}
		}
        public ActionResult Edit(UserStatus status)
        {
            var redis = new RedisClient();

            using (var redisstatus = redis.GetTypedClient<UserStatus>())
            {
                var item = redisstatus.GetById(63138688);

                item.name = status.name;
                item.description = status.description;

                // redisstatus.Store(item);

                
            }

            return RedirectToAction("Index");
        }
        public ActionResult Create(UserStatus status)
        {
            if (ModelState.IsValid)
            {
                var redis = new RedisClient();

                using (var redisStatus = redis.GetTypedClient<UserStatus>())
                {
                    redisStatus.Store(new UserStatus { id = (int) redisStatus.GetNextSequence(), name = status.name, description = status.description });
                }

                return RedirectToAction("Index");
            }
            else
            {
                ViewBag.status = "Invalid";
                return View();
            }
        }
Exemplo n.º 15
0
        public static List<KeyValuePair<string, string>> GetKeysAndValues()
        {
            List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();
            using (IRedisClient client = new RedisClient())
            {

                var objClient = client.GetTypedClient<string>();

                var keys = objClient.GetAllKeys().Where(x => x.StartsWith(keyPredicate));

                foreach (var key in keys)
                {
                    var hash = objClient.GetHash<string>(key);
                    var word = key.Substring(keyPredicate.Length);
                    var val = hash[word];
                    result.Add(new KeyValuePair<string, string>(word, val));
                }
            }

            return result;
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            /*** String ***/
            using (IRedisNativeClient client = new RedisClient())
            {
                client.Set("urn:messages:1", Encoding.UTF8.GetBytes("Hello C# World!"));
            }

            using (IRedisNativeClient client = new RedisClient())
            {
                var result = Encoding.UTF8.GetString(client.Get("urn:messages:1"));
                Console.WriteLine("Message: {0}", result);

            }
            /*** Lists ***/
            using (IRedisClient client = new RedisClient())
            {
                var customerNames = client.Lists["urn:customernames"];
                customerNames.Clear();
                customerNames.Add("Joe");
                customerNames.Add("Mary");
                customerNames.Add("Bob");
            }

            using (IRedisClient client = new RedisClient())
            {
                var customerNames = client.Lists["urn:customernames"];

                foreach (var customerName in customerNames)
                {
                    Console.WriteLine("Customer {0}", customerName);
                }
            }
            /*** Object ***/
            long lastId = 0;
            using (IRedisClient client = new RedisClient())
            {
                var customerClient = client.GetTypedClient<Customer>();
                var customer = new Customer()
                {
                    Id = customerClient.GetNextSequence(),
                    Address = "123 Main St",
                    Name = "Bob Green",
                    Orders = new List<Order>
                    {
                        new Order { OrderNumber = "AB123"},
                        new Order { OrderNumber = "AB124"}
                    }
                };
                var storedCustomer = customerClient.Store(customer);
                lastId = storedCustomer.Id;
            }

            using (IRedisClient client = new RedisClient())
            {
                var customerClient = client.GetTypedClient<Customer>();
                var customer = customerClient.GetById(lastId);

                Console.WriteLine("Got customer {0}, with name {1}", customer.Id, customer.Name);
            }
            /*** Transaction ***/
            using (IRedisClient client = new RedisClient())
            {
                var transaction = client.CreateTransaction();
                transaction.QueueCommand(c => c.Set("abc", 1));
                transaction.QueueCommand(c => c.Increment("abc", 1));
                transaction.Commit();

                var result = client.Get<int>("abc");
                Console.WriteLine(result);
            }
            /*** Publishing & Subscribing ***/
            using (IRedisClient client = new RedisClient())
            {
                client.PublishMessage("debug", "Hello C#!");

                var sub = client.CreateSubscription();
                sub.OnMessage = (c, m) => Console.WriteLine("Got message {0}, from channel {1}", m, c);
                sub.SubscribeToChannels("news");
            }

            Console.ReadLine();
        }
Exemplo n.º 17
0
 private void SetChanges(string modelId, PlayEvent<StubModel> evt)
 {
     using (var redisClient = new RedisClient())
     {
         var redis = redisClient.GetTypedClient<PlayEvent<StubModel>>();
         redis.Lists["urn:changes:" + modelId].Append(evt);
         Console.Write(evt.ToString());
     }
 }
        public JsonResult Delete(int id)
        {
            var redisclient = new RedisClient();

            using (var redisstatus = redisclient.GetTypedClient<UserStatus>())
            {
                redisstatus.DeleteById(58883296);
            }

            return Json(new { id = id }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            //Can't load 900000-600000 from 1 key -> buffer to small
            //Can't save 1300000 to 1 key -> ?

            //50 mb
            //Took 3531.25ms to store (300000 records in 1 key)
            //Took 2953.125ms to load (300000 records from 1 key)
            //Removed all keys from db
            //Took 17765.625ms to store (300000 records in list)
            //Took 3140.625ms to load (300000 records from list)
            ///************************************
            //Took 5265.625ms to store (500000 records in 1 key)
            //Took 4921.875ms to load (500000 records from 1 key)
            //Removed all keys from db
            //Took 29531.25ms to store (500000 records in list)
            //Took 5359.375ms to load (500000 records from list)

            //noute
            //Took 4243,2427ms to store (300000 records in 1 key)
            //Took 4480,2562ms to load (300000 records from 1 key)
            //Took 4448,2544ms to load (1 item from 1 key): test Description _Description_0
            //Removed all keys from db
            //Took 30159,725ms to store (300000 records in list)
            //Took 4279,2447ms to load (300000 records from list)
            //Took 22,0013ms to load (1 item from 1 key): test Description _Description_100
            //Removed all keys from db
            //************************
            //Testing Raven DB...

            //Took 14101,8066ms to store (30000 records in 1 key)
            //Took 10028,5736ms to load (30000 records from 1 key)

            //tst redis
            int totalRecords = 300000;
            //int totalRecords = 30000;
            var trans = new List<Transaction>();
            for (int i = 0; i < totalRecords; i++)
            {
                trans.Add(new Transaction() { Description = "test Description _Description_" + i, Id = i });
            }

            var before = DateTime.Now;

            //TimeSpan exp = new TimeSpan(0, 2400, 0);
            using (var redisClient = new RedisClient())
            {
                var typedRedis = redisClient.GetTypedClient<List<Transaction>>();
                typedRedis.SetEntry("test", trans);
            }
            Console.WriteLine("Took {0}ms to store ({1} records in 1 key)", (DateTime.Now - before).TotalMilliseconds, totalRecords);

            before = DateTime.Now;
            using (var redisClient = new RedisClient())
            {
                var typedRedis = redisClient.GetTypedClient<List<Transaction>>();
                trans = typedRedis["test"];
            }
            Console.WriteLine("Took {0}ms to load ({1} records from 1 key)", (DateTime.Now - before).TotalMilliseconds, trans.Count);

            before = DateTime.Now;
            using (var redisClient = new RedisClient())
            {
                var typedRedis = redisClient.GetTypedClient<List<Transaction>>();
                trans = typedRedis["test"];
            }
            Console.WriteLine("Took {0}ms to load (1 item from 1 key): {1}", (DateTime.Now - before).TotalMilliseconds, trans[0].Description);

            using (var redisClient = new RedisClient())
            {
                redisClient.FlushAll();
            }
            Console.WriteLine("Removed all keys from db");

            using (var redisClient = new RedisClient())
            {
                var typedRedis = redisClient.GetTypedClient<Transaction>();
                var currStat = typedRedis.Lists["test"];
                //trans.ForEach(x => currStat.Add(x));
                currStat.AddRange(trans);
            }
            Console.WriteLine("Took {0}ms to store ({1} records in list)", (DateTime.Now - before).TotalMilliseconds, totalRecords);

            before = DateTime.Now;
            using (var redisClient = new RedisClient())
            {
                var typedRedis = redisClient.GetTypedClient<Transaction>();
                var currStat = typedRedis.Lists["test"];
                trans = currStat.GetAll();
            }
            Console.WriteLine("Took {0}ms to load ({1} records from list)", (DateTime.Now - before).TotalMilliseconds, trans.Count);

            before = DateTime.Now;
            using (var redisClient = new RedisClient())
            {
                var typedRedis = redisClient.GetTypedClient<Transaction>();
                var currStat = typedRedis.Lists["test"];
                var tr = new Transaction() { Id = 100 };
                var res = currStat[currStat.IndexOf(tr)];
                Console.WriteLine("Took {0}ms to load (1 item from 1 key): {1}", (DateTime.Now - before).TotalMilliseconds, res.Description);
            }

            using (var redisClient = new RedisClient())
            {
                redisClient.FlushAll();
            }
            Console.WriteLine("Removed all keys from db");

            /*Console.WriteLine("trying to fill all memory");
            using (var redisClient = new RedisClient())
            {
                var typedRedis = redisClient.GetTypedClient<Transaction>();
                var currStat = typedRedis.Lists["test"];
                int i = 0;
                while (true)
                {
                    var tr = new Transaction() { Description = "test Description _Description_" + i, Id = i };
                    currStat.Add(tr);
                    i++;
                }
            }*/
            Console.ReadLine();
            return;

            //Raven DB

            Console.WriteLine("Testing Raven DB...");
            Console.WriteLine("");

            var rtrans = new TransactionsList();
            rtrans.Transactions = new List<Transaction>();
            for (int i = 0; i < totalRecords; i++)
            {
                rtrans.Transactions.Add(new Transaction() { Description = "test Description _Description_" + i, Id = i });
            }

            var store = new DocumentStore { Url = "http://localhost:8080" };
            store.Initialize();
            before = DateTime.Now;
            using (var session = store.OpenSession())
            {
                session.Store(rtrans, "trans");
                session.SaveChanges();
            }
            Console.WriteLine("Took {0}ms to store ({1} records in 1 key)", (DateTime.Now - before).TotalMilliseconds, totalRecords);

            before = DateTime.Now;
            using (var session = store.OpenSession())
            {
                var order = session.Load<TransactionsList>("trans");
                Console.WriteLine("Took {0}ms to load ({1} records from 1 key)", (DateTime.Now - before).TotalMilliseconds, order.Transactions.Count);
            }

            //Load of 300000:
            //simple-4900ms
            //list-4600ms

            //Save of 300000:
            //simple-3200ms
            //list-15300ms
            Console.ReadLine();
            return;
        }