Something like a tag cache and querying it for suggesting them using Redis

后端 未结 1 2037
-上瘾入骨i
-上瘾入骨i 2021-01-17 07:35

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

相关标签:
1条回答
  • 2021-01-17 07:48

    After googling a lot, I found a good post about something that fits what I was asking for here at StackOverflow:

    • http://robots.thoughtbot.com/post/48851498400/redis-partial-word-match-you-auto-complete-me

    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!

    0 讨论(0)
提交回复
热议问题