The issue is that redis.As<Person>()
returns an entire Generic Redis Client that's typed to the Person entity which is clearer if you remove Type Inference for redisPerson:
IRedisTypedClient<Person> redisPerson = redis.As<Person>();
redis.StoreAsHash(redisPerson);
So this code attempts the improper usage of trying to serialize and save an entire Typed Redis Client using an untyped RedisClient which is not what you want to do, instead you should use the typed redisPerson
Redis Client to save Person
entities, here's a proper example of your program:
class Program
{
static void Main(string[] args)
{
var clientManager = new BasicRedisClientManager("127.0.0.1:6379");
var person = new Person { Id = 1, Name = "Maria" };
using (var redis = clientManager.GetClient())
{
var redisPerson = redis.As<Person>();
redisPerson.StoreAsHash(person);
var fromRedis = redisPerson.GetFromHash(person.Id);
fromRedis.PrintDump();
}
Console.ReadLine();
}
}
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
Which outputs:
{
Id: 1,
Name: Maria
}
Also note that most Typed API's require each Entity to have an Id primary key which is used to create the key the entity is stored at. See this answer for more info on how complex types are stored in ServiceStack.Redis.