博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自己动手搭建 Redis 环境,并建立一个 .NET HelloWorld 程序测试(转)
阅读量:4539 次
发布时间:2019-06-08

本文共 3410 字,大约阅读时间需要 11 分钟。

关于  ,下面来自百度百科:

redis是一个key-value 。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list( )、set(集合)、zset(sorted set --有序集合)和hashs(哈希类型)。这些 都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,redis支持各种不同方式的排序。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步。
Redis 是一个高性能的key-value数据库。 redis的出现,很大程度补偿了 这类key/value存储的不足,在部 分场合可以对关系数据库起到很好的补充作用。它提供了Python,Ruby,Erlang,PHP客户端,使用很方便。

上次测试了 ,今天决定试试这个 。

由于 Redis 部署在 Linux 环境下性能优于 Windows,于是就打算在虚拟机 ubuntu 环境下部署,然后在 Windows 8 下测试。

1. 去下载 Redis 解压和安装,我下载的 2.8.0-rc2。

$ wget http://redis.googlecode.com/files/redis-2.6.15.tar.gz$ tar xzf redis-2.6.15.tar.gz$ cd redis-2.6.15$ make

2. 编译后的可执行文件在src目录中,可以使用下面的命令运行Redis:

$ src/redis-server

 

3. 你可以使用内置的客户端连接Redis:

$ src/redis-cliredis> set foo barOKredis> get foo"bar"

 

4. 在 Windows 下新建 .NET 程序测试。

如果连不上

成功的情况下

测试代码:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using ServiceStack.Redis;using System.Threading;namespace RedisTutorial{    class Program    {        static void Main(string[] args)        {            using (var redisClient = RedisManager.GetClient())            {                using (var cars = redisClient.GetTypedClient
()) { if (cars.GetAll().Count > 0) cars.DeleteAll(); var dansFord = new Car { Id = cars.GetNextSequence(), Title = "张三的汽车", Make = new Make { Name = "宝马" }, Model = new Model { Name = "奔驰" }}; var beccisFord = new Car{Id = cars.GetNextSequence(),Title = "李四的汽车",Make = new Make { Name = "本田" },Model = new Model { Name = "福特" }}; var vauxhallAstra = new Car{Id = cars.GetNextSequence(),Title = "王五的汽车",Make = new Make { Name = "比亚迪" },Model = new Model { Name = "通用" }}; var vauxhallNova = new Car{Id = cars.GetNextSequence(),Title = "赵六的汽车",Make = new Make { Name = "大众" },Model = new Model { Name = "奥迪" }}; var carsToStore = new List
{ dansFord, beccisFord, vauxhallAstra, vauxhallNova }; cars.StoreAll(carsToStore); Console.WriteLine("Redis 有-> " + cars.GetAll().Count + " 辆汽车。"); cars.ExpireAt(vauxhallAstra.Id, DateTime.Now.AddSeconds(5)); Thread.Sleep(6000); Console.WriteLine("Redis 有-> " + cars.GetAll().Count + " 辆汽车。"); var carsFromRedis = cars.GetAll().Where(car => car.Make.Name == "比亚迪"); foreach (var car in carsFromRedis) { Console.WriteLine("Redis 有 ->" + car.Title); } } } Console.ReadLine(); } } public class Car { public long Id { get; set; } public string Title { get; set; } public string Description { get; set; } public Make Make { get; set; } public Model Model { get; set; } } public class Make { public int Id { get; set; } public string Name { get; set; } } public class Model { public int Id { get; set; } public Make Make { get; set; } public string Name { get; set; } }}

 

配置文件:

测试代码下载:

参考:

其它资源:

谢谢浏览!

转载于:https://www.cnblogs.com/tonykan/p/3961943.html

你可能感兴趣的文章
模态窗口缓存无法清除怎么办? 在地址上加个随机数吧"&rd=" + new Date().getTime()
查看>>
阿里的weex框架到底是什么
查看>>
Tesis enDYNA
查看>>
FxZ,C#开发职位面试测试题(30分钟内必须完成)
查看>>
[HNOI2007]分裂游戏
查看>>
Pandas基本介绍
查看>>
当拖动滚动条时 出现小图标
查看>>
LeetCode "Shortest Word Distance II"
查看>>
绕过阿里云防火墙继续扫描探测和SQL注入
查看>>
ln 软链接与硬链接
查看>>
JQuery ajax请求一直返回Error(parsererror)
查看>>
利用POI 技术动态替换word模板内容
查看>>
LeetCode No.168
查看>>
纪录jmeter loop controller 使用中的一个坑
查看>>
spring读取配置文件,且获取bean实例
查看>>
Xcode7 免证书真机测试
查看>>
史上最简单MySQL教程详解(基础篇)之数据类型
查看>>
802.11 帧封装细节
查看>>
flask 基本配置和参数解释
查看>>
HDMI转EDP芯片NCS8803简介
查看>>