关于ServiceStack.Redis实体存储常用的有一下几个方法
StoreAsHash<T>(T entity) //将对象按照Hash存储
Redis.As<T>().Store(); //通过 IRedisTypedClient 将对象存入列表
Redis.As<T>().StoreAll();// 通过IRedisTypedClient 批量将对象存入列表
至于对象的读取通过GetById();
声明对象类时需包含Id字段(注意大小写),以便用于查询
public class ManagerInfo
{
public int Id { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public DateTime CreateTime { get; set; }
}
using (IRedisClient db = RedisManager.GetClient())
{
//db.StoreAll<UserInfo>(list);
//var userinfos = db.As<UserInfo>();
// db.Store<UserInfo>(new UserInfo() { CreateTime = DateTime.Now, Password = "12345", ID = 10, UserName = "fehu" });
for (int i = 3000; i < 3050; i++)
{
db.StoreAsHash(new ManagerInfo() { CreateTime = DateTime.Now, Password = "12345", Id = i, UserName = "fehu" + i.ToString() });
}
}