シゴトでココロオドル
• RDB
– デフォルト
–非同期スナップショット
• forkして書き込むので親processでdisk I/O発生しない
– 履歴バックアップしやすい
– リスタート時の読み込みがはやい
– 数分のデータロスの可能性
• AOF
– 追記型
• disk seekが発生しない
– RDBのログ相当(PostgreSQLのWAL)
• 再生可能
– スナップショットよりサイズが大きい
– 単独で使わない方がいい
• 作者は将来統合したいと思っている
– “we'll likely end up unifying AOF and RDB into a single persistence model
in the future (long term plan).”
ディスク永続化
http://redis.io/topics/persistence
シゴトでココロオドル
• noeviction
– don'texpire at all, just return an error on write operations
– デフォルト。キャッシュとして使わない場合
• volatile-lru
– remove the key with an expire set using an LRU algorithm
– キャッシュとデータ永続化を両方使いたい場合
• allkeys-lru
– remove any key according to the LRU algorithm
– 冪乗則のアクセスパターンの場合
– まよったらこれ
• 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)
– キャッシュ生成時によいTTLを設定できるならこれ
• EXPIRE使うとメモリを余計にとる
• キャッシュとデータ永続化は別々のRedisインスタンスにするのがオススメ
maxmemoryに達した場合の挙動
http://redis.io/topics/lru-cache
シゴトでココロオドル
redis-rails で使えないコマンドが使える
コマンドがそのままメソッド名になっている
# Removethe last element in a list, append it to another list and return it.
#
# @param [String] source source key
# @param [String] destination destination key
# @return [nil, String] the element, or nil when the source key does not exist
def rpoplpush(source, destination)
synchronize do |client|
client.call([:rpoplpush, source, destination])
end
end
redis gem