Programming

Redis

What is Redis?

Redis takes its name from Remote Dictionary Server. Salvatore Sanfilippo opened it in 2009. The main place is working memory, not the disk. That is why a read is fast. When the machine turns off, data that stayed only in memory can go. Writing to disk is turned on separately: a snapshot, or a journal of operations. MySQL keeps rows and columns. Redis keeps keys. One is not the other's name.

What is Redis used for?

Redis is for an answer that is asked often, a session number, and a counter that lasts a short time.

  • Keeping a ready answer for the same page
  • Tying a login session to a number
  • Counting a one-minute limit
  • Adding a short job to a queue

What can you do with Redis?

With Redis you write a value to a key, read it, and set a time. When the time ends, the key is deleted. It does not fit as the main place of an order. An order should stay in a table that remains on disk. Redis can be the quick copy of that table.

Is Redis hard to learn?

Writing one key is easy. The difficulty is the memory filling up. Putting everything into Redis fills the machine. A key without a time can stay. If writing to disk is not on when the server turns off, the last change can go. Do not keep a password or the main row of a payment here.

Advantages and limits

Advantage: a read is fast, the time deletes by itself, and the same answer is not calculated again. Limit: memory is expensive and there is a risk when it turns off. Redis does not replace MySQL. It keeps the layer that is looked at quickly.

Basic ideas

A key is a name. A value is the data tied to that name. The time says when the key will be deleted.

  • SET writes a value
  • GET reads the value
  • EX sets the time in seconds
  • Memory is faster than disk, but it fills

A short example

This writes text to one key and says to delete it after 60 seconds. It does not create a table.

SET page:home "ready" EX 60

Common questions

  • Are Redis and MySQL the same? No. MySQL keeps tables. Redis keeps keys, and its main place is memory.
  • Does everything stay when the machine turns off? Only if writing to disk is on. If not, the last change in memory can go.
  • Is a password stored here? No. What stays here is something that is deleted quickly and read quickly.