admin管理员组

文章数量:1353289

I want to implement lexicographic search (range queries) in Redis as a way to do text search. This is for contexts where RediSearch is not available such as Upstash or Valkey (Redis fork) (edit: supported through valkey-search). I do not want to create a new Redis module or extend the Redis core, but rather implement the functionality in client side using existing Redis primitives.

I'm considering a naive approach using a secondary index (sorted set) where each word is added with the same score:

ZADD myindex 0 "apple" 0 "banana" 0 "kiwi"

Then to search for values starting with "bana":

ZRANGEBYLEX myindex "[bana" "[bana\xff"

Would this approach work for basic lexicographic searches? I'm also interested in implementing something more efficient like a suffix trie similar to what Redis Search uses with FT.CREATE, but I'm not sure what Redis primitives would be appropriate for that implementation.

Has anyone implemented something similar or can suggest the right approach for efficient lexicographic range queries in Redis?

Note that @upstash/query aims to achieve a similar functionality but lexicographic is not implemented and the project seems abandoned.

本文标签: Lexicographic search in Redis without RediSearchStack Overflow