8

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 ?

gbarillot
  • 309
  • 1
  • 2
  • 13

3 Answers3

4

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.

Eli
  • 36,793
  • 40
  • 144
  • 207
  • Yes Eli, finally it appears you are totally right. I did my experiment until the end and benchmarked a reverse index based search using Redis vs ThinkingSphinx indexing... ThinkingSphinx won the battle (nearly 30% faster). So you're right, I think Redis is just not the right tool here, I'll continue to use Sphinx wich is crazy fast (and my legacy MySQL DB wich is crazy big, full of readonly datas...) – gbarillot Jun 18 '13 at 11:58
  • 1
    By the way, just FYI in you're googling to this, the 3 millions records set fits in 650Mo of RAM, so it was a less important issue that I was expected at the beginning – gbarillot Jun 18 '13 at 12:02
2

Here's my take on Redis. Basically I think of it as an in-memory cache that can be configured to only store the least recently used data (LRU). Which is the role I made it to play in my use case, the logic of which may be applicable to helping you think about your use case.

I'm currently using Redis to cache results for a search engine based on some complex queries (slow), backed by data in another DB (similar to your case). So Redis serves as a cache storage for answering queries. All queries either get served the data in Redis or the DB if it's a cache-miss in Redis. So, note that Redis is not replacing the DB, but merely being an extension via cache in my case. This fit my specific use case, because the addition of Redis was supposed to assist future scalability. The idea is that repeated access of recent data (in my case, if a user does a repeated query) can be served by Redis, and take some load off of the DB.

Basically my Redis schema ended up looking somewhat like the duplication of your index you outlined above. I used sets and sortedSets to create "batches / sets" of redis-keys, each of which pointed to specific query results stored under a particular redis-key. And in the DB, I still had the complete data set and an index.

If your data set fits on RAM, you could do the "table dump" into Redis, and get rid of the need for MySQL. I could see this working, as long as you plan for persistent Redis storage and plan for the possible growth of your data, if this "table" will grow in the future.

So depending on your actual use case and how you see Redis fitting into your stack, and the load your DB serves, don't rule out the possibility of having to do both of the options you outlined above (which happend in my case).

Hope this helps!

chinnychinchin
  • 5,564
  • 2
  • 21
  • 18
1

Redis does provide Full Text Search with RediSearch.

Redisearch implements a search engine on top of Redis. This also enables more advanced features, like exact phrase matching, auto suggestions and numeric filtering for text queries, that are not possible or efficient with traditional Redis search approaches.

Guy Korland
  • 9,139
  • 14
  • 59
  • 106