我刚开始使用ServiceStack,并在MVC4中创建了我的第一个服务。现在我想通过Redis来持久化我的对象。我无法弄清楚如何在Windows上运行它,或者ServiceStack分发版本是否已包含此功能。我也考虑使用Redis云实现之一,但首先想在本地运行它。
谢谢。
谢谢。
do more than "download" and "execute installer to get robust service" like you do with Nuget packages
接着我就找到了这个Redis Nuget,它允许您从命令行运行Redis,由MSOpenTech发布,您可以使用ServiceStack.Redis package与之配合使用。
编辑 这是使用它的方法:run the following code:
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();
}
输出:
1 Hi there
2 Hello world
3 Many name is
4 Uh, my name is
(All done, press enter to exit)