Redis full text search : reverse indexing or sunspot?

gbarillot picture gbarillot · Jun 16, 2013 · Viewed 10.6k times · Source

I have 3,5 millions records (readonly) actually stored in a MySQL DB that I would want to pull out to Redis for performance reasons. Actually, I've managed to store things like this into Redis :

1 {"type":"Country","slug":"albania","name_fr":"Albanie","name_en":"Albania"}
2 {"type":"Country","slug":"armenia","name_fr":"Arménie","name_en":"Armenia"}
...

The key I use here is the legacy MySQL id, so with some Ruby glue, I can break as less things as possible in this existing app (and this is a serious concern here).

Now the problem is when I need to perform a search on the keyword "Armenia", inside the value part. Seems like there's only two ways out :

Either I multiplicate Redis index :

Either I use sunspot or some full text search engine (unfortunatly, I actually use ThinkingSphinx which is too much tied to MySQL :-(

So, what would you do ? Do you think the MySQL to Redis move of a single table is even a good idea ? I'm afraid of the Memory footprint those gigantic Redis key/values could take on a 16GB RAM Server.

Any feedback on a similar Redis usage ?

Answer

Eli picture Eli · Jun 17, 2013

Before I start with a real answer, I wanted to mention that I don't see a good reason for you to be using Redis here. Based on what types of use cases it sounds like you're trying to do, it sounds like something like elasticsearch would be more appropriate for you.

That said, if you just want to be able to search for a few different fields within your JSON, you've got two options:

  1. Auxiliary index that points field_key -> list_of_ids (in your case, "Armenia" -> 1).
  2. Use Lua on top of Redis with JSON encoding and decoding to get at what you want. This is way more flexible and space efficient, but will be slower as your table grows.

Again, I don't think either is appropriate for you because it doesn't sound like Redis is going to be a good choice for you, but if you must, those should work.