Tôi không nghĩ rằng câu hỏi có liên quan đến quản lý bộ nhớ ảo, nhưng thêm về hết các mục trong Redis, đó là một chủ đề hoàn toàn khác nhau.
Trái với memcached, Redis không chỉ là bộ nhớ cache. Vì vậy, người dùng có nghĩa vụ phải chọn về chính sách gỡ bỏ mục sử dụng các cơ chế khác nhau. Bạn có thể đuổi tất cả các đồ của bạn, hoặc chỉ một phần của chúng.
Chính sách chung nên được chọn trong file cấu hình với các thông số maxmemory và maxmemory-chính sách, decribed dưới đây:
# Don't use more memory than the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys with an
# EXPIRE set. It will try to start freeing keys that are going to expire
# in little time and preserve keys with a longer time to live.
# Redis will also try to remove objects from free lists if possible.
#
# If all this fails, Redis will start to reply with errors to commands
# that will use more memory, like SET, LPUSH, and so on, and will continue
# to reply to most read-only commands like GET.
#
# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
# 'state' server or cache, not as a real DB. When Redis is used as a real
# database the memory usage will grow over the weeks, it will be obvious if
# it is going to use too much memory in the long run, and you'll have the time
# to upgrade. With maxmemory after the limit is reached you'll start to get
# errors for write operations, and this may even lead to DB inconsistency.
#
maxmemory <bytes>
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached? You can select among five behavior:
#
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly 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)
# noeviction -> don't expire at all, just return an error on write operations
#
# Note: with all the kind of policies, Redis will return an error on write
# operations, when there are not suitable keys for eviction.
#
# At the date of writing this 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 volatile-lru
# LRU and minimal TTL algorithms are not precise algorithms but approximated
# algorithms (in order to save memory), so you can select as well the sample
# size to check. For instance for default Redis will check three keys and
# pick the one that was used less recently, you can change the sample size
# using the following configuration directive.
#
maxmemory-samples 3
Sau đó, cá nhân hàng hết hạn có thể được thiết lập bằng cách sử dụng lệnh sau: EXPIRE EXPIREAT Thuộc tính hết hạn cho mỗi mục hữu ích với các chính sách dễ bay hơi *. Hết hạn cũng có thể được xóa bằng cách sử dụng PERSIST.
Thuộc tính hết hạn thêm chi phí bộ nhớ nhỏ, vì vậy nó chỉ nên được sử dụng nếu được yêu cầu.
Cuối cùng, điều đáng nói là một phần của đối tượng không thể hết hạn, chỉ toàn bộ đối tượng. Ví dụ: toàn bộ danh sách hoặc tập hợp tương ứng với một khóa có thể hết hạn, nhưng không thể danh sách cá nhân hoặc mục được đặt.
Tuyệt vời, cảm ơn. Vì vậy, thuật toán LRU defaul chính xác là những gì tôi muốn. Chỉ cần thiết lập nó để nó là một máy chủ 'nhà nước'. – joedevon