IT > stdout.in Ievgen Kuzminov IT blog

How Redis expires keys

redis

I am often asked by my "junior" colleagues - what happens with Redis keys after expiry time, are these expired keys automatically being deleted or are they just "hang in RAM till The End Of Times" ? *Dramatic music! :)*
Fine, if you are to lazy to read docs...

Redis keys are expired in two ways: a passive way and an active way.

Active

When client access key and the key is found to be timed out - it is being deleted.

Passive

The most interesting - what happens with keys that are expired are are never accessed after expiry.
10 times per second Redis check 100 random keys with associated expiry time from the keyspace and remove expired keys.
If more than 25 keys were expired, start check again.

This is a probabilistic algorithm, where the percentage of keys that are likely to be expired is under 25%. This means that at any given moment the maximum amount of keys already expired that are using memory is at max equal to max amount of write operations per second divided by 4. That means that about 1/4 of RAM occupied by Redis could be used to store "expired" keys.


Grand opening ! ;)

open

Here we go !

It took just a little more that 1 year from idea of having own blog to it's implementation :) Upcoming Yii2 inspired me to have a tight look on it ... and to do something - so this is what I got up to date.

What I have learned while making this blog

  • Yii2 going to be much better that Yii1 and it is worth of switching on it
  • Composer is cool, you can leave without... before you try it. After that - it is very hard without it
  • Namespaces + Composer's autoloader in PHP are cool, that's a pleasure now to write code (with good IDE autocomplete)
  • Markdown is cool, integrated it in this blog, very handy to write formatted posts now

What next :

  • Automatic target "_blank" assiging to markdown parsed links
  • Make page caching
  • Redis cache storage
  • Static pages functionality (veeery static)
  • Tags manipulation/autocomplete functionality + widget (selectize.js) for blog admin
  • Full-text search, experiment with PostgreSQL ts_vector/ts_query, in any case Sphinx is always here to help
  • Nginx + PHP-FPM (I want to try how it goes)
  • Multy-language separation on blog to have Russian and Deutsch (Es wird Spaß machen) sections
  • Full dynamic and relevant OG tags generation

So that's pretty large plans, furthermore I want to make a copule Yii2 extensions/widgets. Really hope to bring something useful this year :)


Ievgen
Kuzminov "iJackUA"
Web Team Lead
at MobiDev (Kharkiv, Ukraine)
Code in Ruby and Elixir, but still love PHP. Explore ES6 and Vue.js. Explore databases, use Ubuntu and MacOS, think about IT people and management

Notes


Have you noticed? Nowadays nobody is doing a New JavaScript framework 😧 These days are over... Everybody is doing their brand new blockchain 😜