类似于标签缓存,并使用Redis对其进行查询以建议他们 [英] Something like a tag cache and querying it for suggesting them using Redis
问题描述
这就像StackOverflow:当您问一个问题时,您需要提供一些标签。
当前,我正在查询关系数据库存储,但是我认为Redis应该有意义为了缓存标签建议。
例如,它将是这样的集合:
sadd标签:建议 c# .net redis
现在,某些用户在问一个问题,他/她可能会写 ne。因此Redis缓存中有一些标签可能与整个部分标签名称匹配: .net 。
我不知道如何与这样的标签相交 tags:uggestions
设置Redis以获得 .net。
还是应该使用字符串而不是字符串?
谢谢!
注意:
对于那些问我要做什么的人,请仔细检查以下问题:我不知道该怎么做,我只是在学习Redis 。 到目前为止,我尝试过什么?阅读手册,使用 set 进行尝试,但是我来到这里是因为我不知道我是否可以使用Redis来实现这一要求...
在进行了很多搜索之后,我发现了一篇很不错的文章,内容适合我在StackOverflow上的要求:
摘要...:
1。为标签创建键值
添加mysite:tags stackoverflow stack-exchange问题 about-redis
2。为每种可能的组合创建索引
是,例如:- s
- st
- sta
-
...等
添加mysite:tags:index:s 1 2
添加mysite:tags:index:st 1 2
添加mysite:tags:index:sta 1 2
添加mysite:tags:index:stack 1 2
添加mysite:tags:index:stacko 1
...依此类推。
这是关于添加所有以 s , st 开头的标签的信息。
3。使用SORT获取标签建议:
按mysort排序mysite:tags:index:s获取标签:*
这将输出:
- stackoverflow
- 堆栈交换
或者...
sort mysite:tags :index:stack- by nosort获取标签:*
...将输出:
- 堆栈交换
这似乎是一个很好的解决方案! / p>
It would be like StackOverflow: when you ask a question you need to provide some tags.
Currently I'm querying the relational database store, but I believe that Redis should make sense in order to cache tag suggestions.
For example, it would be a set like this:
sadd tags:suggestions "c#" ".net" "redis"
Now some user is asking a question and he/she may write "ne" so there's some tag in the Redis cache that may match the whole partial tag name: .net.
I can't figure out how I would intersect such tags:suggestions
Redis set in order to get ".net".
Or should I use a string instead of a set?
Thank you in advance!
Note:
For those asking "what I've tried so far", please double-check the question: I can't figure out what to do, I'm just learning Redis. What I've tried so far? Reading the manual, trying it using a set, but I came here because I don't know if I can implement such requirement with Redis...
After googling a lot, I found a good post about something that fits what I was asking for here at StackOverflow:
Summary...:
1. Create key-values for tags
sadd mysite:tags "stackoverflow" "stack-exchange" "question" "about-redis"
2. Create an index for each possible combination
Yes, for example:
- "s"
- "st"
- "sta"
... and so on
sadd mysite:tags:index:s 1 2
sadd mysite:tags:index:st 1 2
sadd mysite:tags:index:sta 1 2
sadd mysite:tags:index:stack 1 2
sadd mysite:tags:index:stacko 1
... and so on.
It's about adding all tags that start with s, st...
3. Using SORT to get tags suggestions:
sort mysite:tags:index:s by nosort get tags:*
This will output:
- stackoverflow
- stack-exchange
Or... sort mysite:tags:index:stack- by nosort get tags:*
...will output:
- stack-exchange
It seems to be a good solution!
这篇关于类似于标签缓存,并使用Redis对其进行查询以建议他们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!