Php-redis Setting the Expiration Time settimeout command line expire
Redis Expiration Time
In Redis terminology, the key that sets the expire time is called the volatile keys. It means unstable key.
No expiration time is set, that is, persistent storage
Key setTimeOut: SetTimeOut (' x ', 3); Set Expiration Time Setex: Setex (' key ', 3600, ' value ') with time-to-live write value
This command is similar to the following two commands:
Keykey# Set the time to live
The difference is that Setex is an atomic (atomic) operation, the correlation value and setting the time to live two actions will be completed at the same time, which is very useful when Redis is used as a cache.
Memcache Expiration Time
Telnet command format
<command name> <key> <flags> <exptime> <bytes>\r\n <data block>\r\n
PHP command format
Add (String $key, mixed $var [, int $flag [, int $expire]])
$key: The key value that will be stored.
$var: Stored values, character types and integers are saved as original values, and other types are automatically serialized for later saving.
$flag: Whether the stored value is compressed with memcache_compressed, true means compression, and false means no compression.
$expire: Stores the expiration time of the value, if 0 means permanent, but also expires after 30, the expiration time can be the number of seconds after expiration, or when it can expire
Memcache is in memory, so after the expiration date, the data is of course no longer available.
Memcache lazy deletion of outdated data
When a value expires, it is not deleted from memory, so when stats statistics, Curr_item has its information. When a new value takes his place, it is used as an empty chunk. When the get value is determined whether it expires, if it expires, returns empty, and empties, the Curr_item is reduced. That is, this expires, just so that the user does not see this data, and did not immediately after the expiration of the memory deleted. This is called inertia failure. The benefit is that the CPU time and the cost of detection are saved.
Redis 1. Valid
is also running in memory, although Redis can do persistence, aof, or snapshots.
When the key is accessed to determine whether the key expires, if it expires, the expiration process. Second, the volatile keys are sampled every second, and if there is an expiration key, all expired keys are processed.
Redis expiration processing mechanism see http://my.oschina.net/u/1466553/blog/332830, written in very detailed.
2. Permanent storage, but when it is not persisted, the data is lost when it is closed or
Memcache and Redis LRU removal mechanism
Principle: When a unit is requested, maintain a counter to determine who has been least recently used.
Note: Even if a key is set to a permanent expiration date, it will be kicked out as well! That is – permanent data is kicked.
PHP operating Redis and memcache expiration time