Exemplo n.º 1
2
        // GET: Tracker
        public ActionResult Index(long userId, int amount = 0)
        {
            using (IRedisClient client = new RedisClient())
            {
                var userClient = client.As<User>();
                var user = userClient.GetById(userId);
                var historyClient = client.As<int>();
                var historyList = historyClient.Lists["urn:history:" + userId];

                if (amount > 0)
                {
                    user.Total += amount;
                    userClient.Store(user);

                    historyList.Prepend(amount);
                    historyList.Trim(0, 4);

                    client.AddItemToSortedSet("urn:leaderboard", user.Name, user.Total);
                }

                ViewBag.HistoryItems = historyList.GetAll();
                ViewBag.UserName = user.Name;
                ViewBag.Total = user.Total;
                ViewBag.Goal = user.Goal;
                ViewBag.UserId = user.Id;
            }

            return View();
        }
Exemplo n.º 2
1
 /// <summary>
 /// Creates a new osm data cache for simple OSM objects kept in memory.
 /// </summary>
 public OsmDataCacheRedis()
 {
     _client = new RedisClient();
     _clientNode = _client.As<RedisNode>();
     _clientWay = _client.As<RedisWay>();
     _clientRelation = _client.As<RedisRelation>();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a new osm data cache for simple OSM objects kept in memory.
 /// </summary>
 /// <param name="redisClient"></param>
 public OsmDataCacheRedis(RedisClient redisClient)
 {
     _client = redisClient;
     _clientNode = _client.As<RedisNode>();
     _clientWay = _client.As<RedisWay>();
     _clientRelation = _client.As<RedisRelation>(); ;
 }
Exemplo n.º 4
0
        /// <summary>
        ///     根据IEnumerable数据添加链表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="listId"></param>
        /// <param name="values"></param>
        /// <param name="timeout"></param>
        public void AddList <T>(string listId, IEnumerable <T> values, int timeout = 0)
        {
            Redis.Expire(listId, 60);
            IRedisTypedClient <T> iredisClient = Redis.As <T>();

            if (timeout > 0)
            {
                Redis.Expire(listId, timeout);
            }
            IRedisList <T> redisList = iredisClient.Lists[listId];

            redisList.AddRange(values);
            iredisClient.Save();
        }
 public ActionResult AboutPhone()
 {
     string message = string.Empty;
     string host = "localhost";
     using (RedisClient redisClient = new RedisClient(host))
     {
         IRedisTypedClient<Phone> phones = redisClient.As<Phone>();
         Phone phoneFive = phones.GetValue(5.ToString());
         if (phoneFive == null)
         {
             // make a small delay
             Thread.Sleep(5000);
             phoneFive = new Phone
             {
                 Id = 5,
                 Manufacturer = "Motorolla",
                 Model = "xxxxx",
                 Owner = new Person
                 {
                     Id = 1,
                     Age = 90,
                     Name = "OldOne",
                     Profession = "sportsmen",
                     Surname = "OldManSurname"
                 }
             };
             phones.SetEntry(phoneFive.Id.ToString(), phoneFive);
         }
         message = "Phone model is " + phoneFive.Manufacturer;
         message += "Phone Owner Name is: " + phoneFive.Owner.Name;
         message += "Phone Id is: " + phoneFive.Id.ToString();
     }
     ViewBag.Message = message;
     return View("Index");
 }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            using (var redisClient = new RedisClient("localhost"))
            {
                while (true)
                {
                    var stopwatch = System.Diagnostics.Stopwatch.StartNew();
                    //Console.WriteLine("ping: " + ping + ", time: " + time);

                    //redisClient.DeleteAll<Counter>();

                    IRedisTypedClient<Counter> redis = redisClient.As<Counter>();

                    //var key = redis.GetAllKeys();

                    var c = redis.GetAndSetValue("the-counter", new Counter());

                    c.Value += 1;

                    redis.GetAndSetValue("the-counter", c);

                    Console.WriteLine("counter: " + c.Value);

                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }
        }
Exemplo n.º 7
0
        public ActionResult Save(string userName, int goal, long? userId)
        {
            using (IRedisClient client = new RedisClient())
            {
                var userClient = client.As<User>();

                User user;
                if (userId != null)
                {
                    user = userClient.GetById(userId);
                    client.RemoveItemFromSortedSet("urn:leaderboard", user.Name);
                }
                else
                {
                    user = new User()
                    {
                        Id = userClient.GetNextSequence()
                    };
                }

                user.Name = userName;
                user.Goal = goal;
                userClient.Store(user);
                userId = user.Id;

                client.AddItemToSortedSet("urn:leaderboard", userName, user.Total);
            }

            return RedirectToAction("Index", "Tracker", new { userId});
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            try
            {
                var redisClient = new RedisClient("10.1.200.83", 6379);
                Console.WriteLine(redisClient.Get<string>("city"));
                Console.WriteLine(redisClient.Get<string>("tongcheng"));
                Console.WriteLine("Test");
                var redisUser = redisClient.As<User>();

                redisUser.Store(new User()
                {
                    Name = "gu yang",
                    Password = "******"

                });

                var user = redisUser.GetAll();
                Console.WriteLine(user.First().Name);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }
Exemplo n.º 9
0
        private static void UsingIRedisTypedClient(RedisClient client)
        {
            var redisTodos = client.As<Todo>();

            // Mark all Todos, that have passed deadline, as DONE

            redisTodos.GetAll()
                      .Where(t => t.Deadline >= DateTime.Now)
                      // Extension method to execute a lambda expression for each element of a IEnumerable<T>
                      .ForEach(t => t.IsDone = true);

            var todo = new Todo()
            {
                Id = redisTodos.GetNextSequence(),
                Text = "Todo created at " + DateTime.Now,
                Deadline = DateTime.Now.AddDays(1),
                IsDone = false,
                AssignedTo = new User()
                {
                    Name = "Nakov"
                }
            };

            redisTodos.Store(todo);
            redisTodos.GetAll()
                      .Print();
        }
Exemplo n.º 10
0
 public ViewResult Teacher()
 {
     using (var redis = new RedisClient(new Uri(connectionString))) {
         var teacher = redis.As<Teacher>().GetAll().FirstOrDefault();
         return View(teacher);
     }
 }
Exemplo n.º 11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        using (var redisClient = new RedisClient("localhost"))
        {
            //DanhMucDal.ClearCache(CacheManager.Loai.Redis);
            //LoaiDanhMucDal.ClearCache(CacheManager.Loai.Redis);

            //var list = DanhMucDal.List;

            var dm = redisClient.As<DanhMuc>();
            var key = string.Format("urn:danhmuc:list");
            var obj = dm.Lists[key];
            Response.Write(obj.Count + "<br/>");
            foreach (var item in obj.ToList())
            {
                Response.Write(string.Format("{0}:{1}", item.Ten,item.LoaiDanhMuc.Ten));
                Response.Write(item.Ten + "<br/>");
            }
            Response.Write("<hr/>");
            foreach (var _key in dm.GetAllKeys())
            {
                Response.Write(string.Format("{0}<br/>", _key));
            }
        }
    }
        public void SaveItem(Item item)
        {
            var conf = new RedisEndpoint() { Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "******", Ssl = true, Port = 6380 };
            using (IRedisClient client = new RedisClient(conf))
            {
                var itemClient = client.As<Item>();
                var itemList = itemClient.Lists["urn:item:" + item.ProductID];
                item.Id = itemClient.GetNextSequence();
                itemList.Add(item);

                client.AddItemToSortedSet("urn:Rank", item.Name, item.Price);

                //Publis top 5 Ranked Items
                IDictionary<string, double> Data = client.GetRangeWithScoresFromSortedSet("urn:Rank", 0, 4);
                List<Item> RankList = new List<Item>();
                int counter = 0;
                foreach (var itm in Data)
                {
                    counter++;
                    RankList.Add(new Item() { Name = itm.Key, Price = (int)itm.Value, Id = counter });
                }

                var itemJson = JsonConvert.SerializeObject(RankList);
                client.PublishMessage("Rank", itemJson);
                //---------------------------------------------
            }
        }
Exemplo n.º 13
0
        public Task<bool> SetAsync(string series, int index, long value)
        {
            using (var client = new RedisClient(Host))
            {
                var cache = client.As<Dictionary<int, long>>();

                if (cache.ContainsKey(series))
                {
                    cache[series][index] = value;
                }
                else
                {
                    lock (cache)
                    {
                        cache.SetValue(series,
                            new Dictionary<int, long>()
                        {
                            [index] = value
                        });
                    }
                }

                return Task.FromResult(true);
            }
        }
Exemplo n.º 14
0
 public void DeleteAllDailyPosts()
 {
     using (var redisClient = new RedisClient("mtl-ba584:6379"))
     {
         var redis = redisClient.As<PostElement>();
         redis.Lists["dailyposts"].RemoveAll();
     }
 }
Exemplo n.º 15
0
 public void DeleteAllTechnologyRadarPosts()
 {
     using (var redisClient = new RedisClient("mtl-ba584:6379"))
     {
         var redis = redisClient.As<PostElement>();
         redis.Lists["technologyradar"].RemoveAll();
     }
 }
Exemplo n.º 16
0
 public void setProductos(IEnumerable<Producto> productos)
 {
     using (IRedisClient redisClient = new RedisClient(host, port, password, 1))//creamos nuestro objeto de conexion.
     {
         //creamos un objeto IRedisTypedClient y le especificamos que trabajara con nuestra clase Producto como tipo.
         IRedisTypedClient<Producto> redisTypeClient = redisClient.As<Producto>();
         redisTypeClient.StoreAll(productos);//almacenamos todos nuestros productos.
     }
 }
Exemplo n.º 17
0
 public void delProductos()
 {
     using (IRedisClient redisClient = new RedisClient(host, port, password, 1))//creamos nuestro objeto de conexion.
     {
         //creamos un objeto IRedisTypedClient y le especificamos que trabajara con nuestra clase Producto como tipo.
         IRedisTypedClient<Producto> redisTypeClient = redisClient.As<Producto>();
         redisTypeClient.DeleteAll();//Eliminamos todos los productos.
     }
 }
Exemplo n.º 18
0
        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());
        }
Exemplo n.º 19
0
 private static void Main(string[] args)
 {
     using (var client = new RedisClient())
     {
         var clientServices = client.As<ServiceDto>();
         services = clientServices.Lists["SERVICE"].ToList();
     }
     services.ForEach(service => SaveResults(InvokeService(service)));
 }
Exemplo n.º 20
0
        /// <summary>
        /// Stores a missing venue in REDIS
        /// </summary>
        /// <param name="venueName">Venue that is missing</param>
        public void StoreMissingVenue(string venueName)
        {
            var redisClient = new RedisClient("localhost");
            var eventClient = redisClient.As<MissingVenueModel>();

            MissingVenueModel missingVenue = new MissingVenueModel { VenueName = venueName, DateMissing = DateTime.UtcNow };

            eventClient.Store(missingVenue);
        }
 public object Get(MessageErrors request)
 {
     var client = new RedisClient();
     using (var store = client.As<MessageError>())
     {
         var list = store.Lists["urn:ServiceErrors:All"];
         return list;
     }
 }
Exemplo n.º 22
0
        public static void Init()
        {
            var uri = new Uri(ConfigurationManager.AppSettings["REDISTOGO_URL"]);
            using (var redis = new RedisClient(uri))
            {
                redis.FlushAll();

                var assignmentsStore = redis.As<Assignment>();
                var assignments = new List<Assignment> {
                    new Assignment {Id = 1, CourseId = 1, Title = "Ch 1, 1-29 Odd", DueDate = new DateTime(2012, 12, 27)},
                    new Assignment {Id = 2, CourseId = 2, Title = "Ch 2, 1-21", DueDate = new DateTime(2012, 12, 28)},
                    new Assignment {Id = 3, CourseId = 2, Title = "Ch 2, 25-28, 29-27 Odd", DueDate = new DateTime(2013, 1, 5)},
                    new Assignment {Id = 4, CourseId = 4, Title = "Ch 3, 33-39, 41", DueDate = new DateTime(2012, 12, 20)}
                };
                assignmentsStore.StoreAll(assignments);

                var coursesStore = redis.As<Course>();
                var courses = new List<Course> {
                    new Course {Id = 1, Period = 1, TeacherId = 1, Subject = "Math", AssignmentIds = new int[] {1}, StudentIds = new int[] {1, 2}},
                    new Course {Id = 2, Period = 2, TeacherId = 1, Subject = "Advanced Math", AssignmentIds = new int[] {2, 3}},
                    new Course {Id = 3, Period = 3, TeacherId = 1, Subject = "Math"},
                    new Course {Id = 4, Period = 4, TeacherId = 1, Subject = "Science", AssignmentIds = new int[] {4}, StudentIds = new int[] {1}},
                    new Course {Id = 5, Period = 5, TeacherId = 1, Subject = "Science", StudentIds = new int[] {2}},
                    new Course {Id = 6, Period = 6, TeacherId = 1, Subject = "Math"},
                    new Course {Id = 7, Period = 1, TeacherId = 2, Subject = "History"}
                };
                coursesStore.StoreAll(courses);

                var teachersStore = redis.As<Teacher>();
                var teacher = new Teacher { Id = 1, Name = "Jane Doe", CourseIds = new int[] { 1, 2, 3, 4, 5, 6 } };
                teachersStore.Store(teacher);

                var studentsStore = redis.As<Student>();
                var students = new List<Student> {
                    new Student {Id = 1, FirstName = "Bill", LastName = "Clinton", Grade = 8, CourseIds = new int[] {1, 4}},
                    new Student {Id = 2, FirstName = "George", LastName = "Bush", Grade = 8, CourseIds = new int[] {1, 5}},
                    new Student {Id = 3, FirstName = "Abraham", LastName = "Lincoln", Grade = 8, CourseIds = new int[0]},
                    new Student {Id = 4, FirstName = "George", LastName = "Washington", Grade = 8, CourseIds = new int[0]},
                    new Student {Id = 5, FirstName = "John", LastName = "Adams", Grade = 8, CourseIds = new int[0]},
                    new Student {Id = 6, FirstName = "Barack", LastName = "Obama", Grade = 8, CourseIds = new int[0]}
                };
                studentsStore.StoreAll(students);
            }
        }
Exemplo n.º 23
0
 private static void SaveResults(ServiceResultsDto serviceResults)
 {
     using (var client = new RedisClient())
     {
         client.Increment("SERVICE_RESULTS_ID", 1);
         serviceResults.Id = client.Get<int>("SERVICE_RESULTS_ID");
         var clientService = client.As<ServiceResultsDto>();
         clientService.Lists["SERVICE_RESULTS"].Add(serviceResults);
     }
 }
 public void SaveProduct(Product product)
 {
     var conf = new RedisEndpoint() { Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "******", Ssl = true, Port = 6380 };
     using (IRedisClient client = new RedisClient(conf))
     {
         var userClient = client.As<Product>();
         product.Id = userClient.GetNextSequence();
         userClient.Store(product);
     }
 }
Exemplo n.º 25
0
        public IEnumerable<PostElement> GetAllTechnologyRadarPostElements()
        {
            using (var redisClient = new RedisClient("mtl-ba584:6379"))
            {
                var redis = redisClient.As<PostElement>();
                var currentPosts = redis.Lists["technologyradar"];

                return currentPosts.ToList();

            }
        }
Exemplo n.º 26
0
        public IEnumerable<PostElement> GetAllDailyPostElements()
        {
            using (var redisClient = new RedisClient("mtl-ba584:6379"))
            {
                var redis = redisClient.As<PostElement>();
                var currentPosts = redis.Lists["dailyposts"];

                return currentPosts.ToList();

            }
        }
Exemplo n.º 27
0
        public void InsertDailyPost(PostElement postElement)
        {
            using (var redisClient = new RedisClient("mtl-ba584:6379"))
            {
                var redis = redisClient.As<PostElement>();
                var currentPosts = redis.Lists["dailyposts"];

                currentPosts.Add(postElement);

            }
        }
Exemplo n.º 28
0
        public void InsertTechnologyRadarPost(PostElement postElement)
        {
            using (var redisClient = new RedisClient("mtl-ba584:6379"))
            {
                var redis = redisClient.As<PostElement>();
                var currentPosts = redis.Lists["technologyradar"];

                currentPosts.Add(postElement);

            }
        }
Exemplo n.º 29
0
 public void AddTrip(Trip T)
 {
     using (var redisManager = new PooledRedisClientManager())
     {
         using (_client = new RedisClient())
         {
             var redisTrip = _client.As<Trip>();
             redisTrip.Store(T);
         }
     }
 }
        public override void Observe()
        {
            RefreshDb();

            _redisClient = new RedisClient(_host);
            _packageClient = _redisClient.As<Package>();

            _package = new Package {Id = Guid.NewGuid()};

            _writeRepository = Container.Resolve<INEventStoreRepository<Package>>();
        }
Exemplo n.º 31
0
        public void Simple()
        {
            ServiceStack.Redis.RedisClient cli = new ServiceStack.Redis.RedisClient();
            var c1   = cli.As <UserLight>();
            var set1 = c1.Sets["set1"];

            //set1.Add(new UserLight() { Id = DateTime.Now.Ticks, UserName = "******", LastSeen = DateTime.Now });

            var s = "activity-" + DateTime.Now.ToString("dd-hh-mm-ss");

            var users = ActivityTracker.GetActiveUsers();
        }
Exemplo n.º 32
-1
 public ViewResult Student()
 {
     using (var redis = new RedisClient(new Uri(connectionString))) {
         var student = redis.As<Student>().GetAll().FirstOrDefault();
         return View(student);
     }
 }