search

Home  >  Q&A  >  body text

redis - 怎样给key排序?

有如下场景,key:A,B,C,准备将他们的组合做key:

A: 1
B: 2
C: 3
AB: 4
AC: 5
BC: 6
ABC: 7

我想询匹配次数最多的key,比如我想查找A,C那么,排序后的结果:

  1. AC

  2. ABC

  3. A

  4. C

这样的在redis里怎么排序查找啊?还是我的设计就有问题啊?请教。

天蓬老师天蓬老师2774 days ago781

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-24 09:15:17

    Redis is a light query NoSQL. Apart from query based on key names, there are almost no other query methods. It is not suitable for databases that use Redis for heavy queries. If you need rich queries, it is recommended to use MongoDb. In comparison, Redis is more suitable for high speed. Read-write, caching system without too many logical dependencies.

    In addition, for your needs, you can put the data involved in sorting into the same hash, read out all the data when using it, and then sort it in the program. But this is just a compromise.

    reply
    0
  • 迷茫

    迷茫2017-04-24 09:15:17

    Use redis’s built-in sortset type to store data. It supports sorce subscript, which is equivalent to an index. It has powerful query, sorting, and range query capabilities. For details, you can see redis’ documentation on the sortset type

    reply
    0
  • 高洛峰

    高洛峰2017-04-24 09:15:17

    Redis only supports one kind of fuzzy query, which is keys. Query based on keywords. Any other data structure is not supported, so your needs cannot be achieved simply through Redis. You can consider other NoSql products, or implement it through indexing.

    reply
    0
  • Cancelreply