memcached and redis

85 views
Skip to first unread message

Robin Lery

unread,
Mar 1, 2014, 4:28:32 PM3/1/14
to django...@googlegroups.com
Hello,
Another noob question. Please bear with me. I am really very confused between memcached and redis. I know they both are used for caching. But I don't know how much does they help. And lastly, I would like know what would you use for a site with users uploaded pictures and videos too? I hope I was clear. If not please ask. Your help and guidance will be very much appreciated.

Thank you.
Robin.

Andreas Kuhne

unread,
Mar 1, 2014, 7:31:41 PM3/1/14
to django...@googlegroups.com
Hi,

In response to your question about memcache and redis, they are extremely useful, if you use them correctly. For example if you are generating a query to your database that takes 1 second to finish, and you cache the results in memcache or redis, then you would be able to get the second request down to 50 ms instead. Thats the difference in response time. Redis and memcache are in memory databases and are extremely fast!

Regarding your second question, if you need to store alot of pictures and videos, I would use Amazon S3 with the django storages backend for S3.

Regards,

Andréas


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B4-nGqoYH24%2BSLzM8Jx3dN_xiPFYpZ90-gqfRNVpcWUEK%3DVsw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Robin Lery

unread,
Mar 1, 2014, 8:00:05 PM3/1/14
to django...@googlegroups.com
Hello,
Thank you for your answer. Would you please elaborate a little more about the use cases with these? And can I use them together?

Thank you.


Andreas Kuhne

unread,
Mar 1, 2014, 8:15:58 PM3/1/14
to django...@googlegroups.com
Hi again,

Do you mean use cases with redis and memcache or with S3?

Regards,

Andréas

Robin Lery

unread,
Mar 1, 2014, 8:27:15 PM3/1/14
to django...@googlegroups.com
Use cases with memcached and redis please.


Andreas Kuhne

unread,
Mar 1, 2014, 8:39:19 PM3/1/14
to django...@googlegroups.com
Ok,

Redis and Memcache really solve the same problems. The main difference is that you can use redis as a session cache for django (save the session objects to memory instead of the database), which I haven't found a solution for memcache yet. Also redis CAN be persisted (saved to disk), if you setup your own redis server.

But otherwise, you can use both memcache and redis for your cache. Examples where a cache can be useful:
1. You want to do a complex database query that takes a long time to run, but doesn't update often. Just cache the results and use the result if it is present.
2. You can also cache the result of a view. If the view takes a long time to render AND is the same for all users, then cache the entire view result. 
3. There is also the possibility to  create portions of a template and cache just those portions.

Thats what I can think of off the top of my head. You can find more information about it here: 

The main thing to remember is that both memcache and redis are in memory databases (key-value store) (even though redis can be persisted) and if the server is rebooted, then the cache is empty. Also being a in memory database means that getting information back from the key-value store is more or less instantanious especially if you compare to a standard sql database.

Regards,

Andréas


Robin Lery

unread,
Mar 1, 2014, 8:48:52 PM3/1/14
to django...@googlegroups.com
Ok, I think I get it now. Thank you so much! Just one more question though, does redis has feature similar to getidentifiable() and putifuntouched() like memcache, I think these are for consistency?


Russell Keith-Magee

unread,
Mar 1, 2014, 11:46:16 PM3/1/14
to Django Users
On Sun, Mar 2, 2014 at 4:39 AM, Andreas Kuhne <andrea...@suitopia.com> wrote:
Ok,

Redis and Memcache really solve the same problems.

Erm… no, they don't.

They are both in-memory stores, but that's where the similarities ends. 

Memcache is a simple in-memory cache, and that's it. It's designed to provide you an easy way to cache common but expensive operations - be that template rendering, view construction, database retrieval operations, or whatever. If an operation is slow to perform, performed frequently, and changes much less frequently than the frequency with which it is called, you can use memcache to insert the computed value into memory, and retrieve it easily when it is next needed. 

Values inserted into memcache are set with an expiry time -- so you can say things like "the content of the homepage is cached for 5 minutes". 

Memcache isn't stored anywhere permanent; if your memcache instance is restarted, you lose everything stored in it. It is, by design a transient data store.

Redis is a much more sophisticated data store than memcache.

At a superficial level, it can be used in the same way as memcache, but with persistence (so if Redis restarts, you don't lose data). However, this only scratches the surface of Redis' capabilities. 

Redis has a whole lot of capabilities for handling sets of data, lists of data, bitmaps, publish/subscribe operations, and much more. Check out the Redis docs [1] if you want to get a feel for what you can do.


So - don't fall into the trap of thinking Redis is "Memcache, but with persistence". Yes, you could use it like this if you wanted to, but it's not the right tool for that job.

Yours,
Russ Magee %-)

Andy McKay

unread,
Mar 1, 2014, 11:53:48 PM3/1/14
to django...@googlegroups.com
On Sat, Mar 1, 2014 at 12:39 PM, Andreas Kuhne <andrea...@suitopia.com> wrote:
The main difference is that you can use redis as a session cache for django (save the session objects to memory instead of the database), which I haven't found a solution for memcache yet.

Robin Lery

unread,
Mar 2, 2014, 9:57:43 AM3/2/14
to django...@googlegroups.com
Thank you Andy and Russel! I guess I know a lot about those two cache methods.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Andreas Kuhne

unread,
Mar 2, 2014, 11:57:42 AM3/2/14
to django...@googlegroups.com
Hi,

I really don't know if they exist. Check redis.io, you should be able to see them there.

Regards,

Andréas


Robin Lery

unread,
Mar 2, 2014, 12:19:46 PM3/2/14
to django...@googlegroups.com
Hello,
Its no bother. Thank you! I have learnt a lot from you guyz!


Reply all
Reply to author
Forward
0 new messages