以cmd安装方法:
现在来观察Redis是怎么持久化存储数据到硬盘上.(快照是默认的持久化方式,默认的文件名称为dump.rdb)
可以看到Redis服务端在一段时间后将数据库保存在磁盘上,文件为:dump.rdb.
以weindows服务安装Redis方法:
Redis Desktop Manager
特点: C++ 编写,响应迅速,性能好.但不支持数据库备份与恢复.
项目地址: https://github.com/uglide/RedisDesktopManager
Redis Client
项目简介: 使用Java编写,功能丰富,缺点是性能稍差,网络不好时,会不时断线.
项目地址: https://github.com/caoxinyu/RedisClient
Redis Studio
项目简介: 又一个C++编写的redis管理工具,仅支持windows平台,支持xp操作系统.
项目地址: https://github.com/cinience/RedisStudio
redisClient的安装及基本使用
①.、使用服务器管理,支持服务器密码认证
新的redis数据:字符串String,列表List,哈希hash,集合set,有序集合Sorted set.
代码示例
static void Main(string[] args) { //在Redis中存储常用的5种数据类型:String,Hash,List,SetSorted set RedisClient client = new RedisClient("172.21.0.192", 6379); #region string client.Add<string>("StringValueTime", "我已设置过期时间噢30秒后会消失", DateTime.Now.AddMilliseconds(30000)); while (true) if (client.ContainsKey("StringValueTime")) Console.WriteLine("String.键:StringValue,值:{0} {1}", client.Get<string>("StringValueTime"), DateTime.Now); Thread.Sleep(10000); else Console.WriteLine("键:StringValue,值:我已过期 {0}", DateTime.Now); break; client.Add<string>("StringValue", " String和Memcached操作方法差不多"); Console.WriteLine("数据类型为:String.键:StringValue,值:{0}", client.Get<string>("StringValue")); Student stud = new Student() { id = "1001", name = "李四" }; client.Add("StringEntity", stud); Student Get_stud = client.Get ("StringEntity"); Console.WriteLine("数据类型为:String.键:StringEntity,值:{0} {1}", Get_stud.id, Get_stud.name); #endregion #region Hash client.SetEntryInHash("HashID", "Name", "张三"); client.SetEntryInHash("HashID", "Age", "24"); client.SetEntryInHash("HashID", "Sex", "男"); client.SetEntryInHash("HashID", "Address", "上海市XX号XX室"); List<string> HaskKey = client.GetHashKeys("HashID"); foreach (string key in HaskKey) Console.WriteLine("HashID--Key:{0}", key); List<string> HaskValue = client.GetHashValues("HashID"); foreach (string value in HaskValue) Console.WriteLine("HashID--Value:{0}", value); List<string> AllKey = client.GetAllKeys(); //获取所有的key. foreach (string Key in AllKey) Console.WriteLine("AllKey--Key:{0}", Key); #endregion #region List /* */ client.EnqueueItemOnList("QueueListId", "1.张三"); //入队 client.EnqueueItemOnList("QueueListId", "2.张四"); client.EnqueueItemOnList("QueueListId", "③王五"); client.EnqueueItemOnList("QueueListId", "④王麻子"); int q = client.GetListCount("QueueListId"); for (int i = 0; i < q; i++) Console.WriteLine("QueueListId出队值:{0}", client.DequeueItemFromList("QueueListId")); //出队(队列先进先出) } client.PushItemToList("StackListId", "1.张三"); //入栈 client.PushItemToList("StackListId", "2.张四"); client.PushItemToList("StackListId", "③王五"); client.PushItemToList("StackListId", "④王麻子"); int p = client.GetListCount("StackListId"); for (int i = 0; i < p; i++) Console.WriteLine("StackListId出栈值:{0}", client.PopItemFromList("StackListId")); //出栈(栈先进后出) } #endregion #region Set无序集合 /* */ client.AddItemToSet("Set1001", "小A"); client.AddItemToSet("Set1001", "小B"); client.AddItemToSet("Set1001", "小C"); client.AddItemToSet("Set1001", "小D"); HashSet<string> hastsetA = client.GetAllItemsFromSet("Set1001"); foreach (string item in hastsetA) Console.WriteLine("Set无序集合ValueA:{0}", item); //出来的结果是无须的 } client.AddItemToSet("Set1002", "小K"); client.AddItemToSet("Set1002", "小C"); client.AddItemToSet("Set1002", "小A"); client.AddItemToSet("Set1002", "小J"); HashSet<string> hastsetB = client.GetAllItemsFromSet("Set1002"); foreach (string item in hastsetB) Console.WriteLine("Set无序集合ValueB:{0}", item); //出来的结果是无须的 } HashSet<string> hashUnion = client.GetUnionFromSets(new string[] { "Set1001", "Set1002" }); foreach (string item in hashUnion) Console.WriteLine("求Set1001和Set1002的并集:{0}", item); //并集 } HashSet<string> hashG = client.GetIntersectFromSets(new string[] { "Set1001", "Set1002" }); foreach (string item in hashG) Console.WriteLine("求Set1001和Set1002的交集:{0}", item); //交集 } HashSet<string> hashD = client.GetDifferencesFromSet("Set1001", new string[] { "Set1002" }); //[返回存在于第一个集合,但是不存在于其他集合的数据.差集] foreach (string item in hashD) Console.WriteLine("求Set1001和Set1002的差集:{0}", item); //差集 } #endregion #region SetSorted 有序集合 /* */ client.AddItemToSortedSet("SetSorted1001", "1.刘仔"); client.AddItemToSortedSet("SetSorted1001", "2.星仔"); client.AddItemToSortedSet("SetSorted1001", "③猪仔"); List<string> listSetSorted = client.GetAllItemsFromSortedSet("SetSorted1001"); foreach (string item in listSetSorted) Console.WriteLine("SetSorted有序集合{0}", item); #endregion }
输出结果:
以上就是土嘎嘎小编为大家整理的redis学习_一)相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!