如何存储在Redis的缓存列表元素 [英] How to store list element in Redis cache

查看:611
本文介绍了如何存储在Redis的缓存列表元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 StackExchange.Redis 的C#Redis的缓存。

  cache.StringSet(KEY1,CustomerObject);

但我想存储像

数据

  cache.StringSet(KEY1,ListOfCustomer);


  

,使得一个键具有存储所有客户列表并且很容易
  搜索,分组,筛选客户数据也是列表里面


答案,欢迎使用 ServiceStack.Redis StackExchange.Redis


解决方案

您可以使用 ServiceStack.Redis 高级别<一个href=\"https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.Interfaces/Redis/Generic/IRedisTypedClient.cs\"相对=nofollow> IRedisTypedClient类型化的API,用于管理丰富的POCO类型

首先得到一个类型的Redis客户,为客户提供:

  VAR redisCustomers = redis.As&LT;客户&GT;();

这将解决高层次类型的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 or StackExchange.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆