redis - 怎样给key排序?
天蓬老师
天蓬老师 2017-04-24 09:13:17
0
3
776

有如下场景,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里怎么排序查找啊?还是我的设计就有问题啊?请教。

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
左手右手慢动作

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.

迷茫

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

小葫芦

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template