Redisのデータ消去戦略

免責事項:この記事はブロガーオリジナル記事です、続くBY-SAのCC 4.0を著作権契約、複製、元のソースのリンクと、この文を添付してください。
このリンク: https://blog.csdn.net/qq_42220174/article/details/102097955

Q:MySQLはデータがRedisの中にホットデータであることを確認する方法を、2000ワットのデータのみ20ワットRedisのデータストアを持っていますか?

:知識:特定のサイズにRedisのメモリデータセットのサイズアップ(maxmemoryの設定)と、彼らはデータ消去戦略(出口戦略)を実行します。Redisのは、6つのデータ消去戦略を提供しています。

MaxMemoryに設けRedisのプロファイルコード(メモリのRedisの最大使用)maxmemory <bytes>、デフォルトでは0バイトです。新しいデータが追加された場合、最大メモリを超え、Redisのは崩壊します。一定の大きさまで上昇するデータセットのRedisのメモリサイズ(maxmemoryの設定)と、彼らはデータ消去の戦略を実行します(出口戦略)Redisのは、政策のうち、6つのデータをサポートし、デフォルトはmaxmemory-policy noeviction:追放を禁止しています。アルゴリズム記述からデータの6種類を、次のとおりです。

  • 揮発性-LRU:削除キーを使用してLRUアルゴリズムでは、有効期限を持っています
  • allkeys-LRU:LRUアルゴリズムに従って、任意のキーを削除します。
  • 揮発性ランダム:期限切れのランダムなセットを持つキーを削除します。
  • allkeysランダム:ランダムなキーを削除
  • 揮発性-TTL:削除キーは最近、時間が経過しました
  • noeviction:絶対に期限が切れるが、書き込み操作はエラーを返しません

ソース構成コードに関連する文書(異なるバージョンが異なる場合があり、元のコードに翻訳されている記述用語を提供することが重要です):

# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
# 单位是不区分大小写的,所以1GB 1Gb 1gB都是一样的
# units are case insensitive so 1GB 1Gb 1gB are all the same.

# WARNING: not setting maxmemory will cause Redis to terminate with an
# out-of-memory exception if the heap limit is reached. 
# 警告:未设置maxmemory将导致Redis在达到堆限制时发生内存不足异常

# maxmemory <bytes>
# 设置最大内存,默认单位是byte,即字节

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
# 最大内存策略:当达到最大内存时,Redis如何选择删除什么。您可以选择五种行为:
#
# volatile-lru -> remove the key with an expire set using an LRU algorithm :使用LRU算法删除具有过期集的密钥
# allkeys-lru -> remove any key according to the LRU algorithm :根据LRU算法删除任何密钥
# volatile-random -> remove a random key with an expire set :删除带有过期集的随机密钥
# allkeys-random -> remove a random key, any key :删除一个随机密钥,任何密钥
# volatile-ttl -> remove the key with the nearest expire time (minor TTL) :删除具有最近过期时间的密钥
# noeviction -> don't expire at all, just return an error on write operations :完全不过期,只是在写操作上返回一个错误
#
# Note: with any of the above policies, Redis will return an error on write
#       operations, when there are no suitable keys for eviction.
# 注意:对于以上任何一种策略,当没有合适的清除键时,Redis将在写操作上返回一个错误。    
#       At the date of writing these commands are: set setnx setex append
#       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
#       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
#       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
#       getset mset msetnx exec sort
#
# The default is:
#  默认的是:最大内存策略:不清除
# maxmemory-policy noeviction

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
# 最大内存策略:当达到最大内存时,Redis将如何选择删除什么。您可以选择五种行为

# LRU and minimal TTL algorithms are not precise algorithms but approximated
# algorithms (in order to save memory), so you can tune it for speed or
# accuracy. For default Redis will check five keys and pick the one that was
# used less recently, you can change the sample size using the following
# configuration directive.
#
# The default of 5 produces good enough results. 10 Approximates very closely
# true LRU but costs a bit more CPU. 3 is very fast but not very accurate.
#
# maxmemory-samples 5

おすすめ

転載: blog.csdn.net/qq_42220174/article/details/102097955