ServiceStack Redis 在检索数据方面是如何工作的 [英] How does ServiceStack Redis function in retrieving data

查看:39
本文介绍了ServiceStack Redis 在检索数据方面是如何工作的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定这是否是问题的最佳标题……也许有人可以为我重命名?

Not sure if it's the best title for the question... maybe someone could rename it for me?

我的问题是关于在 Redis 的 c# ServiceStack 包装器中读取和组合数据的性能以及调用在内部如何工作.

My question is regarding performance of reading and combining data in c# ServiceStack wrapper for Redis and how the calls work internally.

我将解释两种可能产生最终结果的场景.一种情况是将类别 ID 列表附加到交易中,以便可以独立存储类别.

I will explain two scenarios that will hopefully yield in a final result. One scenario has the list of category id's attached to the Transaction so that the Category can be stored independently.

问题:我的最终目标是检索所有属于食物"类别的交易.

Question: My end goal is to retrieve all transactions that have category 'food'.

我已经尝试对其他点进行编号,在这些点上清晰有助于我的理解.假设有 10,000 笔交易,每笔交易平均有 3 个类别.

I have tried to number other points where clarity would help my understanding. Consider there being 10,000 transactions and each transaction had on average 3 categories.

注意:ServiceStack.Net Redis:存储相关对象与相关对象 Id 但是没有解释效率.

示例 A

public class Transaction
{
    public List<string> CategoryIds;
}

示例 B

public class Transaction
{
    public List<string> CategoryNames;
}

代码

var transactionClient = redisClient.GetTypedClient<Transaction>();

//1. is this inefficient returning all transactions?
//   is there any filtering available at this part?
var allTransactions = transactionClient.GetAll();

//2. In the case of Example A where the categories are stored as id's
//   how would I map the categories to a transaction?
//   maybe I have a List that has a container with the Transaction associated with a
//   list of Categories, however this seems inefficient as I would have to loop 
//   through all transactions make a call to get their Categories and then 
//   populate the container datatype.

//3. If we are taking Example B how can I efficiently just retrieve the transactions
//   where they have a category of food.

推荐答案

效率是更少的网络调用 vs 更多的数据.Redis 中的数据只是被弄脏了,大多数情况下,单个 API 调用与 Redis 服务器操作是 1:1 映射的.这意味着您可以将性能影响视为简单地从远程服务器的内存中下载一个 json 数据集 blob 并在客户端上对其进行反序列化 - 这实际上就是所有发生的事情.

The efficiency is less network calls vs more data. Data in Redis just gets blobbed, most of the time a single API call maps 1:1 with a redis server operation. Which means you can think about the perf implications as simply downloading a json dataset blob from a remote server's memory and deserializing it on the client - which is effectively all that happens.

在某些 API 中,例如 GetAll() 它需要 2 次调用,1 次获取实体集中的所有 id,另一个获取具有这些 id 的所有记录.Redis Client 的源代码非常平易近人,所以我建议看看到底发生了什么.

In some APIs such as GetAll() it requires 2 calls, 1 to fetch all the ids in the Entity set, and the other to fetch all the records with those ids. The source code of the Redis Client is quite approachable so I recommend having a look to see exactly what's happening.

因为您只有 3 个类别,所以通过尝试在服务器上进行过滤,您节省的额外数据并不多.

Because you've only got 3 categories, it's not that much extra data you're saving by trying to filter on the server.

所以你的选择基本上是:

So your options are basically:

  • 下载整个实体数据集并在客户端进行过滤
  • 从类别">ID"维护自定义索引映射
  • 更高级:使用服务器端 LUA 操作来应用服务器端过滤(需要 Redis 2.6)

这篇关于ServiceStack Redis 在检索数据方面是如何工作的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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