3

I've just got started with ServiceStack and have created my first service in MVC4. Now I want to persist my objects using Redis. I can't figure out how to get it running on Windows or if the ServiceStack distribution already has this included. I'm also thinking about using one of the Redis cloud implementations, but I'd like to get it running locally first.

Thanks

1 Answer 1

7

You need something like Redis on Windows (here and here, for blog posts about that). You can use the repo stored on github. Once you have that you can build redis in Visual Studio and run it.

Service Stack also has a support page here, including a link to a project that runs Redis as a Windows Service.

Edit. And I've found the project and blog post I played with a month or so ago as well (which coincidentally is written by Jason from stackexchange).

LATE UPDATE Ok, so no sooner had I commented

do more than "download" and "execute installer to get robust service" like you do with Nuget packages

than I find this Redis Nuget that allows you to run Redis from the command line, released by MSOpenTech that you can use with the ServiceStack.Redis package

Edit and this is how you use it:

  • Create a console application in Visual Studio
  • Run "manage NuGet packages" in the project console menu on solution explorer
  • Search for, and install "redis-64" and "ServiceStack.Redis" (you may want to do redis-64 by running install-package redis-64 from the Package Manager Console)
  • Start redis from packages\Redis-64.\tools\redis-server.exe by cmd prompt or double click
    • (If asked about windows firewall, just cancel to keep comms on the local machine)
  • 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(); } 

Output:

1 Hi there 2 Hello world 3 Many name is 4 Uh, my name is (All done, press enter to exit) 
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. I did try the repo stored on github, but just pulling the zip file it did not compile. I will try again using git.
@TrevordeKoekkoek. Visual Studio spoils us so much that I also admit to being thrown a bit when I had to do more than "download" and "execute installer to get robust service" like you do with Nuget packages - you just have to change gears a bit and you'll be ok.
@TrevordeKoekkoek. Wow, literally posted that comment and thought "wonder what's on Nuget now" - then find redis-64 was added on Monday, May 6, 2013. Answer edited for our collective edification.
@TrevordeKoekkoek. I've added a working sample tested using VS2012.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.