I have an array of item like {code: 'item code', desc: 'item desc'}
where I have to perform LIKE
comparison with them; which is exactly like what LIKE
works in SQL.
Is there anyway to do this with redis?
I have an array of item like {code: 'item code', desc: 'item desc'}
where I have to perform LIKE
comparison with them; which is exactly like what LIKE
works in SQL.
Is there anyway to do this with redis?
There is no like operator for Redis but the author of Redis has a nice article on how to implement autocomplete: http://oldblog.antirez.com/post/autocomplete-with-redis.html
If you use a sorted set with same score for all the items, then you can use ZSCAN command to match with a glob-style pattern.
For example:
redis> ZADD z 0 one 0 two 0 three 0 four
(integer) 4
redis> ZSCAN z 0 match *o*
1) "0"
2) 1) "four"
2) "0"
3) "one"
4) "0"
5) "two"
6) "0"