如何在Windows上的Servicestack上开始使用Redis?

Tre*_*oek 3 asp.net-mvc redis servicestack asp.net-mvc-4

我刚开始使用ServiceStack并在MVC4中创建了我的第一个服务.现在我想使用Redis保留我的对象.我无法弄清楚如何让它在Windows上运行或者ServiceStack发行版已经包含了这个.我也在考虑使用其中一个Redis云实现,但我想先让它在本地运行.

谢谢

And*_*own 7

你需要像Windows上的Redis这样的东西(这里这里,关于它的博客文章).您可以使用存储在github上repo.完成后,您可以在Visual Studio中构建redis并运行它.

Service Stack 在此处还有一个支持页面,包括指向将Redis作为Windows服务运行的项目的链接.

编辑.我已经找到我大约一个月前玩过的项目和博客文章(巧合的是由来自stackexchange 的杰森撰写).

晚了更新好的,所以我评论之后不久

不仅仅是"下载"和"执行安装程序以获得强大的服务",就像使用Nuget软件包一样

我发现这个Redis Nuget允许你从命令行运行Redis,由MSOpenTech发布,你可以使用ServiceStack.Redis

编辑,这是你如何使用它:

  • 在Visual Studio中创建控制台应用程序
  • 在解决方案资源管理器的项目控制台菜单中运行"管理NuGet包"
  • 搜索并安装"redis-64"和"ServiceStack.Redis"(您可能希望通过从软件包管理器控制台运行install-package redis-64来执行redis-64)
  • 通过cmd提示符从packages\Redis-64.\ tools\redis-server.exe启动redis或双击
    • (如果被问及Windows防火墙,只需取消以保持本地计算机上的通信)
  • 运行以下代码:

    public class Message {
        public long Id { get; set; }
        public string Payload { get; set; }
    }
    
    static void Main(string[] args) {
        List<string> messages = new List<string> {
            "Hi there",
            "Hello world",
            "Many name is",
            "Uh, my name is"
        };
    
        var client = new RedisClient("localhost");
        var msgClient = client.As<Message>();
    
        for (int i = 0; i < messages.Count; i++) {
            Message newItem = new Message { 
                Id = msgClient.GetNextSequence(), 
                Payload = messages[i] };
            msgClient.Store(newItem);
        }
    
        foreach (var item in msgClient.GetAll()) {
            Console.WriteLine("{0} {1}", item.Id, item.Payload);
            msgClient.DeleteById(item.Id);
        }
    
        Console.WriteLine("(All done, press enter to exit)");
        Console.ReadLine();
    }
    
    Run Code Online (Sandbox Code Playgroud)

输出:

1 Hi there 
2 Hello world 
3 Many name is 
4 Uh, my name is 
(All done, press enter to exit)
Run Code Online (Sandbox Code Playgroud)