-1

I am new to service stack redis api. So i am getting little confused while using the service stack redis api. I want to know IRedisTypedClient"<"T">"?
1) What stands for "<"T">"?
2) What are the parameters we can pass in the "<"T">"?

1 Answer 1

2

The IRedisTypeClient interface provides a typed version of the Redis Client API where all its API's accept a typed POCOs (i.e. Plain Old CSharp Object) for its value body which is in contrast to IRedisClient which just accepts raw strings. Behind the scenes the Typed API's just serialize the POCO's to a JSON string but it's typed API provides a nicer API to work with when dealing with rich complex types.

The API to create a IRedisTypeClient<T> is to use the IRedisClient.As<T> API, e.g:

public class Todo { public long Id { get; set; } public string Content { get; set; } public int Order { get; set; } public bool Done { get; set; } } IRedisClient redis = redisManager.GetClient(); var redisTodos = redis.As<Todo>(); 

As seen above you can create a typed API from any user-defined POCO, which now provides API's that lets you work directly native Todo types, e.g:

var todo = new Todo { Id = redisTodos.GetNextSequence(), Content = "Learn Redis", Order = 1, }; redisTodos.Store(todo); Todo savedTodo = redisTodos.GetById(todo.Id); savedTodo.Done = true; redisTodos.Store(savedTodo); "Updated Todo:".Print(); redisTodos.GetAll().ToList().PrintDump(); 

There's a stand-alone version of this example as well as a Live Demo of Backbones TODO app with a Redis backend which makes use of the RedisClient Typed API.

Sign up to request clarification or add additional context in comments.

4 Comments

I am using the visual studio 2010 .NET Framework 4.0. I have included the servicestack API by NuGet. In this environment still the POCO is serialized as a JSON string or any thing else?
@Immanuel POCO's are always serialized as JSON behind the scenes, but this is just an impl detail you shouldn't have to worry about.
Is it in Any platform we use stackservice redis the poco will always serialized as JSON?
@Immanuel yes, there aren't any differences between platforms.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.