Redis 对二级索引的支持 [英] Redis Support on Secondary index
问题描述
redis 是否支持对字符串数据类型的二级索引?
Does redis provide support for secondary index on string data type?
我已经安装了 redis 服务器来检查,但无法清楚地找到这样做.
I have installed redis server to check that, but could not find out clearly to do this.
我想知道如何将数据与辅助密钥一起存储在 redis 中.
I would like to know how i can store the data in redis along with seconday key.
例如,我想存储车辆 ID:- 注册号,在我的情况下,这将是主键,车辆颜色:- 红色,这可能是次要键,与车辆信息相关的有效载荷是我的价值.现在,我还想在redis中找到所有颜色为红色的payload.
Example let say i want to store thevehicle id:- registration no, in my case this will be primary key, vehicle color:- Red, this could be secondary key and payload related to vehicle info is my value. Now, I also want to find all payload whose color is red in redis.
就像我在 MySql 中可以做的一样
Same as like i can do in MySql like
Select * from table where secondarycolumn="red"
Select * from table where secondarycolumn="red"
另外,我想知道在使用主键在 redis 中设置值时,如何为其设置二级索引值.
Also, I would like to know while setting value in redis using primary key, how can i set the secondary index value for it.
推荐答案
您可以通过部署 RediSearch.
RediSearch 支持定义哈希字段的自动索引,然后使用简单的查询短语轻松查询这些索引.
RediSearch supports defining automatic indexing of the hash fields and then to easily query those indexes using a simple query phrase.
例如
FT.SEARCH myIdx "@name:Joe @age:[70-90]"
这篇关于Redis 对二级索引的支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!