0

I am trying to use redis as a cache layer for my mongodb database, my requirement is i have cities collection which consists of all cities of Asia continent and Europe continent and on this data i need to perform search by city name with regex and pagination. I am dumping all cities collection into redis zset. The problem is when i able to do pagination but not able to do search with case sensitive using zscan and match. Please help me out is my approach with redis is right or wrong.

Ramesh Paul
  • 840
  • 4
  • 15
  • 31

1 Answers1

1

I don't know about right and wrong, but here's how I'd go about this with Redis: The MATCH clause does glob-style matching so when you need more robust expression that's a problem. There are three basic approaches you could try in that case:

  1. try to normalize your searches to glob-style, if possible, e.g. by always doing lowercase searches (and keeping the data the same)
  2. try using ZRANGEBYLEX, possibly using the information at http://redis.io/topics/indexes
  3. use Lua scripts to implement the regex logic, e.g. https://stackoverflow.com/a/29945372/3160475

Also note, about pagination with ZSCAN, that the COUNT switch is only a hint.

Community
  • 1
  • 1
Itamar Haber
  • 47,336
  • 7
  • 91
  • 117