1

I would like to store serialized objects in Redis from a database table with a compound primary key of two values. The objects might look like the following in code:

Public Class Contact
    Public Property Instance_Id() As Long
    Public Property Contact_Id() As Long
    Public Property First_Name() As String
    Public Property Last_Name() As String
End Class

The Instance_Id is shared amongst a group of contacts, and the Contact_Id value is unique to each contact.

What is the fastest and most memory efficient way to store these objects in Redis where I can retrieve all the Contacts with a specific Instance_Id, or just the one Contact with a specific Contact_Id ?

4

1 回答 1

3

我会为表单的每个联系人构建一个哈希(contact_id => Contact 类数据),可以通过键(contact_id)直接查询以解决您的特定查找情况。然后,添加一组(已排序,如果您关心排序)(instance_id => [contact_id1, contact_id2, ... , contact_idN])。要通过 instance_id 进行查找,您将从一个查询中的索引集中获取 contact_ids,然后对于您返回的每个 id,对每个这些 id 进行特定的查找。

从 RDBMS 的角度来看,我意识到这听起来很疯狂,因为您习惯于将查询视为昂贵的操作。Redis 命令的设计速度非常快,因此发送大量命令来执行 RDBMS 中的一个查询是相当有效的。

于 2013-06-10T01:50:12.963 回答