Redis persistence mechanism and expired

Redis persistence mechanism and expired

1. persistence mechanism

1.1 RDB (default)

  • mechanism
    • Within a specified time, a specified number of write operations -> Data in memory will be written to disk (dump.rdb file)
    • Redis will reboot to load the disk has been persistent data
  • Advantages: recovery speed, suitable for most scenes
  • Disadvantages: data integrity, consistency is not high (because before if data in memory is written to disk, the program hung up or down, will lead the new data is not persistent)

1.2 AOF

  • mechanism
    • Will each write operation by way of the log record and append to a file
    • Restart Redis will read the log file for recovery
  • Advantages: data integrity, higher consistency
  • Disadvantages: more logging, recovery is slow

2. Expiration mechanism

2.1 deleting data according to expiration policies

  • Regularly delete: low memory usage and high CPU consumption. Once every 100ms random sample (100 key), delete the expired key. If you remove the key more than 25% of the total sample (ie, 25), then the next immediately a spot check.
  • Inert Delete: high memory footprint and low CPU consumption. When the key is accessed, it checks whether the key expires, if you delete this key expired, and return empty.
  • Periodic Delete: Delete the timing and inert deleted binding version. If you delete a higher frequency, into the timing. If deletion low frequency, into inert deleted.

2.2 When the memory is too large fit new data, will enable the elimination mechanism

  • In order to prevent general Redis memory footprint is too large, affecting the entire server, sets the maximum memory values ​​that maxmemory
  • When the memory above maxmemory, will release the memory according to maxmemory_policy
    • noeviction: when new data is written directly to an error
    • allkeys-lru: when writing new data, delete all the key data in the least recently used
    • allkeys-lfu: when writing new data, delete all data in the frequency of use minimal key
    • allkeys-random: when writing new data, delete the random key data for all
    • volatile-lru: when writing new data, deleting data expiration time set in the key of the least recently used
    • volatile-lfu: when writing new data, deleting data set expiration time of the rarest frequency key
    • volatile-random: when new data is written randomly delete data expiration time set in the key
    • volatile-ttl: When writing new data, delete the expired time earlier priority key
  • supplement
    • LRU -> least recently used
    • LFU -> least frequently used

other

  • The reason fast Redis
    • Pure memory operation
    • epoll is single-threaded, not multi-threaded and locking switch
Published 128 original articles · won praise 45 · Views 150,000 +

Guess you like

Origin blog.csdn.net/alionsss/article/details/103721462