Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis as a cache and a queue using same instance

My application requires two use-cases for a cache:

  1. Redis as a cache. I plan to cache items (JSON blobs) by id using allkeys-lru memory policy. Average JSON item will take <1 Mb.
  2. Redis as a queue. I decided to build content social feed (similar to Instagram or Facebook) using Redis queue API. It will use same memory policy. Capacity of a queue will be ~1000 elements. Average queue (which represents a feed per user) will take ~10 Mb.

Can i use a single instance of Redis for both purposes without performance impact? Is it better to split them for better performance? Thank you.

like image 421
Andrii Skaliuk Avatar asked Nov 02 '25 14:11

Andrii Skaliuk


2 Answers

There is no reason not to try; I would recommend using two databases within the same redis instances however, so that if you ever want to up size to two separate instances, you can dump and relocate on db separate from the other.

Two instances would be faster than one, but no sense doubling the cost until you have some idea what your needs are - but keeping the db's separate will make that process a bit less painful if it comes to that.

like image 134
E.J. Brennan Avatar answered Nov 05 '25 06:11

E.J. Brennan


Redis is single-threaded, so you get more CPU power with 2 redis instead of one. Still you will need to manage 2 databases (can be great for scaling, but it will need more actions for backups etc).

If you don't need a lot of CPU power in redis (with functions that requires a lot of computations, like in LUA scripts) I don't think you will see a big difference by using 2 redis instead of one. Most of the time, it is I/O that is the slowest part that drives the performance and as Redis is an in-memory database, it won't have a big impact.

like image 35
zenbeni Avatar answered Nov 05 '25 05:11

zenbeni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!