-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">"?

JACOB DEEPAK
  • 21
  • 1
  • 11

1 Answers1

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.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • 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? – JACOB DEEPAK Dec 02 '14 at 04:53
  • @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. – mythz Dec 02 '14 at 11:09
  • Is it in Any platform we use stackservice redis the poco will always serialized as JSON? – JACOB DEEPAK Dec 02 '14 at 11:16
  • @Immanuel yes, there aren't any differences between platforms. – mythz Dec 02 '14 at 11:29