Distributed memcached Learning (2) -- Basic memcached commands and basic memcached commands
The above section describes how to compile and log on to memcahed in linux. The following describes how to use the basic memcahed commands.
Add
Function: adds a new cache record to the memory.
Syntax: add key flag expire length
Resolution:
Key indicates a unique name for the value to be stored.
Flag, which must be a positive integer
The validity period of the expire cache record, in seconds. If it is set to 0, it will not automatically expire.
Length (in bytes)
For example:
Removable
Run add name 0 0 4. enter the value to be saved. After enter, the system prompts "stored", indicating that the storage is successful. We can use the get command to obtain this value:
Validity
The image is extracted successfully. If the validity period is set to 5 seconds, the value cannot be extracted after 5 seconds, as shown below:
Uniqueness
You cannot add an existing key to the memory. If a record whose key is name already exists, you cannot add another key. As follows:
Delete
Function: deletes a cache record from the memory.
Syntax: delete key
Resolution:
Key of the cache record to be deleted
For example:
Get
Function: extract a cache record from memory
Syntax: get key
Resolution:
Key of the cache record to be extracted
For example:
Replace
Function: replaces cache records in the memory.
Syntax: replace key flag expire length
Resolution:
Key of the cache record to be replaced
Flag, which must be a positive integer
The validity period of the expire cache record, in seconds. If it is set to 0, it will not automatically expire.
Length (in bytes)
For example:
It can be seen that the value of the record with the key of year is replaced with 2016.
Note: replace can be performed only when a key exists.
Set
Function: set or replace the cache records in the memory, which is equivalent to the add + replace function.
If this key is not in the server cache, a record is added. If the server has this key, the record is modified.
Syntax: set key flag expire length
Resolution:
Key of the cache record to be set or replaced
Flag, which must be a positive integer
The validity period of the expire cache record, in seconds. If it is set to 0, it will not automatically expire.
Length (in bytes)
For example:
Modify record
It can be seen that the value of the record with the key of year is replaced with 20160101.
Add record
It can be seen that the record whose key is date is added to the cache.
The basic commands of Memcached are learned here. Next we will discuss the memory management mechanism of Memcached.