Redis itself does not support it. We have modified the source code of Redis so that it can support full-text search, string search, and some calculations of summation and average.
Project homepage: http://oncedb.com
Full text search
OnceDB supports direct search, supports objects such as String and Hash,
Search string: search pattern operator value
Use the SEARCH command
# Create data
set test1 'this is testing'
> OK
set test2 'this is article'
> OK
# Search data
search test* ~ article
1) test1
2) this is testing
3) test2
4) this is article
Operator supports:
= Exact match
~ Partial match
> >= < <= Compare match
Search hash: hsearch pattern field operator value ...
Use the hsearch command
There is no concept of "table" in redis. Generally, the key name using schema:id includes the table name and the primary key. For example, user:001 is a hash object with a user table and a primary key value of 001.
# Create hash data
hmset user:001 name kris email [email protected] gender male age 16
> OK
hmset user:002 name sunny age 24
> OK
# Search hash data
hsearch user:* age > 18 name = *
1) user:002
2) 24
3) sunny
Search ordered list(zset): zhsearch key from to schema field operator value ...
Use test:* or user:* pattern matching directly, because it will traverse all the keys, and the performance is low. zhsearch can search the corresponding primary key in an ordered list and specify the search scope.
In the above example, we store the primary key value of user into the *user ordered list, and the score is an integer about time
zadd *user 20020201 001 20020202 002
Search for the first matching data (from 0 to 0)
zhsearch *user 0 0 user: age > 10
1) -1
2) user:001
3) 16
When using full-text search, the first parameter returned is always -1.
OnceDB does not change the data storage structure of Redis. Redis database files can be directly operated in OnceDB and then returned to Redis for use.
Index query
The performance of full-text search is poor. You can improve the performance by creating indexes.
OnceDB can choose to automatically create auxiliary indexes when data is modified.
Detailed information can refer to this answer
Redis and Querying Values