private static void TestList() { using (var client = new RedisClient("127.0.0.1", 6379)) { #region "List类型" client.AddItemToList("HQF.Tutorial.Redis:userInfoId1", "123"); client.AddItemToList("HQF.Tutorial.Redis:userInfoId1", "1234"); Console.WriteLine("List数据项条数:" + client.GetListCount("HQF.Tutorial.Redis:userInfoId1")); Console.WriteLine("List数据项第一条数据:" + client.GetItemFromList("HQF.Tutorial.Redis:userInfoId1", 0)); Console.WriteLine("List所有数据"); client.GetAllItemsFromList("HQF.Tutorial.Redis:userInfoId1").ForEach(e => Console.WriteLine(e)); #endregion #region "List类型做为队列和栈使用" Console.WriteLine(client.GetListCount("HQF.Tutorial.Redis:userInfoId1")); //队列先进先出 //Console.WriteLine(client.DequeueItemFromList("userInfoId1")); //Console.WriteLine(client.DequeueItemFromList("userInfoId1")); //栈后进先出 Console.WriteLine("出栈" + client.PopItemFromList("HQF.Tutorial.Redis:userInfoId1")); Console.WriteLine("出栈" + client.PopItemFromList("HQF.Tutorial.Redis:userInfoId1")); #endregion } }
static void Main(string[] args) { var redisClient = new RedisClient("121.199.25.195", 6379); redisClient.AddItemToList("list", "11"); var aa = redisClient.Lists["list"]; Console.WriteLine(aa.Count); Console.WriteLine(aa[0]); ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("yhdcache0.redis.cache.windows.net,ssl=false,password="); }
public ActionResult data_to_redis() { DataTable table = GetDataTable("select distinct road from familiarrealty_f.houseinfo"); HashSet<string> non_rep_address = new HashSet<string>(); List<String> json_strings = new List<String>(); ServiceStack.Redis.RedisClient redis = new ServiceStack.Redis.RedisClient(); redis.FlushDb(); foreach (DataRow row in table.Rows) { var json_result = new { road = row["road"].ToString() }; redis.AddItemToList("road:geo", json_result.ToJSON()); json_strings.Add(json_result.ToJSON()); non_rep_address.Add(json_result.ToJSON()); } //Response.Write(String.Format(@"non_rep_address count is {0},json_string_count is {1}",non_rep_address.Count,json_strings.Count)); return new RenderJsonResult { Result = json_strings }; }
public void Add(string item) { client.AddItemToList(listId, item); }