如何存储在Redis的缓存列表元素 [英] How to store list element in Redis cache
问题描述
我用 StackExchange.Redis
的C#Redis的缓存。
cache.StringSet(KEY1,CustomerObject);
但我想存储像
数据 cache.StringSet(KEY1,ListOfCustomer);
,使得一个键具有存储所有客户列表并且很容易
搜索,分组,筛选客户数据也是列表里面
块引用>答案,欢迎使用
ServiceStack.Redis
或StackExchange.Redis
解决方案首先得到一个类型的Redis客户,为客户提供:
VAR redisCustomers = redis.As<客户>();
这将解决高层次类型的API来管理客户POCO的那则让你坚持单一客户有:
redisCustomers.SetEntry(的customer1,CustomerObject);
或顾客的一个列表:
redisCustomers.Lists [客户]的AddRange(ListOfCustomer)。
I have used
StackExchange.Redis
for c# redis cache.cache.StringSet("Key1", CustomerObject);
but I want to store data like
cache.StringSet("Key1", ListOfCustomer);
so that one key has all Customer List stored and it is easy to search,group,filter customer Data also inside that List
Answers are welcome using
ServiceStack.Redis
orStackExchange.Redis
解决方案You can use ServiceStack.Redis high-level IRedisTypedClient Typed API for managing rich POCO Types.
First get a typed Redis client for Customers with:
var redisCustomers = redis.As<Customer>();
Which will resolve a high-level typed API for managing Customer POCO's that then lets you persist a single Customer with:
redisCustomers.SetEntry("Customer1", CustomerObject);
Or a list of Customers with:
redisCustomers.Lists["Customers"].AddRange(ListOfCustomer);
这篇关于如何存储在Redis的缓存列表元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!