Redis as Key/Value Store and MySQL as Persistence

1,117 views
Skip to first unread message

forumu...@gmail.com

unread,
Jul 9, 2014, 5:45:59 AM7/9/14
to redi...@googlegroups.com
Had anyone worked on integrating Redis & MySQL (Redis as Key/Value Store and MySQL as Persistence store).

Basically using the Redis as Cache and using MySQL for permanent data store.

Please suggest steps/configuration needed in using Redis as Key/Value Store and MySQL as Persistence

Thanks in advance.

Josiah Carlson

unread,
Jul 9, 2014, 12:47:42 PM7/9/14
to redi...@googlegroups.com
There are literally thousands of people doing this right now.

Steps:
1. Install MySQL
2. Install Redis
3. Install client libraries for both
4. Read the documentation and use them as per your requirements

If you have problems along the way, ask specific questions with information about what you were doing, what you want to do, and what you were having a problem with.

If this reply wasn't what you were looking for, it is because your original post is roughly equivalent to, "I'd like to drive a car on the road, can someone tell me how to drive a car on the road?"

 - Josiah




--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

forumu...@gmail.com

unread,
Jul 9, 2014, 2:40:37 PM7/9/14
to redi...@googlegroups.com

forumu...@gmail.com

unread,
Jul 9, 2014, 2:43:11 PM7/9/14
to redi...@googlegroups.com
Thanks for the reply.

My requirement is as mentioned: Redis as Key/Value Store and MySQL as Persistence store

Whenever a request comes, initially i need to check the record in the redis database, if the record is not present in the redis database then i need to fetch from the MySQL.

Any references on configuring the Redis & MySQL. I tried to check books and googled a lot, but could not find any configuration/documentation on this.

Any documentation references would be helpful.

Thanks in advance.

Itamar Haber

unread,
Jul 9, 2014, 2:59:07 PM7/9/14
to redi...@googlegroups.com

I believe what you're missing here is that this isn't a configuration issue but rather something that needs to be implemented by your application's logic. Here's a short snippet in pseudo python that demonstrates how you can cache calls to your database:

def get_results(sql):
hash = md5.new(sql).digest()
result = redis.get(hash)
if result is None:
result = db.execute(sql)
redis.set(hash, result)
return result

Of course, you may want to tweak and change this pattern to suit your own needs.

Cheers,
Itamar

--

forumu...@gmail.com

unread,
Jul 9, 2014, 10:48:49 PM7/9/14
to redi...@googlegroups.com
Thanks for the reply.

very new to this - 
Is there any setting in Redis, that says use the MySQL as the persistence database, and also to keep data sync with some interval? Please suggest.

Thanks in advance.

Josiah Carlson

unread,
Jul 10, 2014, 12:47:17 AM7/10/14
to redi...@googlegroups.com
There is no such setting. The closest thing that Redis has is the ability to asynchronously replicate data to a slave Redis server. But still, Redis does not persist to non-Redis servers, and does not make requests to any non-Redis servers.

As Itamar said, any behavior that you want from Redis must be implemented in your application.

 - Josiah



Josh Berkus

unread,
Jul 11, 2014, 5:25:53 PM7/11/14
to redi...@googlegroups.com
On 07/09/2014 09:47 PM, Josiah Carlson wrote:
> There is no such setting. The closest thing that Redis has is the
> ability to asynchronously replicate data to a slave Redis server. But
> still, Redis does not persist to non-Redis servers, and does not make
> requests to any non-Redis servers.

There's some connectors for PostgreSQL and Redis:

http://pgxn.org/dist/redis_fdw/
https://bitbucket.org/IVC-Inc/redis_wrapper

You could probably do creative things with them to guarantee
persistence. Additionally, when Postgres BDR becomes a reality (~~
January), you could write a replication tool which would accept redis
replication and push the data into Postgres.

However, your bigger issue is how, exactly, would you map Redis data to
relational tables? That's fairly obvious with some data types, but not
with others.

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com

Javier Guerra Giraldez

unread,
Jul 11, 2014, 5:37:19 PM7/11/14
to redi...@googlegroups.com
On Fri, Jul 11, 2014 at 4:25 PM, Josh Berkus <jo...@agliodbs.com> wrote:
> However, your bigger issue is how, exactly, would you map Redis data to
> relational tables? That's fairly obvious with some data types, but not
> with others.


the real question is not about mapping Redis into relational, but
mapping application data into both Redis and relational. Since that's
obviously application-dependent, the final solution is better done in
the application and not on some 'settings'

--
Javier
Reply all
Reply to author
Forward
0 new messages