In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Blog outline:
First, store commonly used instructions
1.set instruction
2.add instruction
3.replace instruction
4.append instruction
5.prepend instruction
6.cas instruction
Second, commonly used search instructions
1.get instruction
2.gets instruction
3.delete instruction
4.incr instruction
5.decr instruction
6.stats instruction
7.stats items instruction
8.stats slabs instruction
9.stats sizes instruction
10.flush_all instruction
First, store commonly used instructions
Common instructions for storing data are:
The set command is to save a data called key to the server; the add command is to add a data to the server, but the server must ensure that the key does not exist and that the data will not be overwritten; the replace command is to replace an existing data, which is similar to the set function if the data does not exist
The syntax format of the above instructions is the same, but the instructions are different. The syntax is as follows:
Each parameter has the following meanings:
: add, set, replace and other instructions;-key: is a unique identifier stored on the server, which cannot conflict with other key, otherwise the original data will be overwritten (if you use the set command), this key is to accurately access a data item;-flag: marks a 16-bit unsigned integer data, which is used to set some interactive operations between the server and the client. -expiration time: the validity period of the data on the server. If it is 0, the data is always valid (in seconds). The Memcached server will set the validity period of a data to the current Unix time + the set valid time;-bytes: the length of the data, the length of the block data data block. Generally, the next line after this length is followed by the block data data content. After sending the data, the client usually waits for the return from the server. 1.set instruction
The set instruction is used to store the data value (value) in the specified key (key). If the set key already has a value, it will overwrite the original value!
Basic grammatical format:
Set key flags exptime bytes [noreply] value
Parameter description:
Key: is the name of the key
Flags: an integer parameter that can include a key-value pair, which can be understood as a key tag
Exptime: length of time to keep key-value pairs in the cache (in seconds, 0 means forever)
Bytes: the number of bytes stored in the cache
Noreply (optional): this parameter tells the server that there is no need to return data
Value: stored value (always on the second line)
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .set lzj 0 8jianjianSTORED
Output information:
STORED: save successfully; ERROR: save failed; 2.add instruction
The add instruction is used to store the value (data value) in the specified key (key). If the key of the add already exists, the data will not be updated (expired key will be updated).
Basic grammatical format:
Add key flags exptime bytes [noreply] value
Parameter description:
Key: is the name of the key
Flags: an integer parameter that can include a key-value pair, which can be understood as a key tag
Exptime: length of time to keep key-value pairs in the cache (in seconds, 0 means forever)
Bytes: the number of bytes stored in the cache
Noreply (optional): this parameter tells the server that there is no need to return data
Value: stored value (always on the second line)
Example:
In the following example, we set:
Key → key
Flag → 0
Exptime → 900 (in seconds)
Bytes → 3 (bytes of data storage)
Value → lzj
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .add key 0900 3lzjSTORED
Output information explanation:
STORED: save successfully; ERROR: save failed; 3.replace instruction
The replace instruction is used to replace the value (data value) of the existing key (key). If the key does not exist, the replacement fails!
The syntax is as follows:
Replace key flags exptime bytes [noreply] value
Parameter description:
Key: is the name of the key
Flags: an integer parameter that can include a key-value pair, which can be understood as a key tag
Exptime: length of time to keep key-value pairs in the cache (in seconds, 0 means forever)
Bytes: the number of bytes stored in the cache
Noreply (optional): this parameter tells the server that there is no need to return data
Value: stored value (always on the second line)
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .add abc 0900 3123STOREDreplace abc 0900 3234STORED
Output information explanation:
STORED: save successfully; ERROR: save failed; 4.append instruction
The append directive is used to append data to the value (data value) of the existing key!
The syntax is as follows:
Append key flags exptime bytes [noreply] value
Parameter description:
Key: is the name of the key
Flags: an integer parameter that can include a key-value pair, which can be understood as a key tag
Exptime: length of time to keep key-value pairs in the cache (in seconds, 0 means forever)
Bytes: the number of bytes stored in the cache
Noreply (optional): this parameter tells the server that there is no need to return data
Value: stored value (always on the second line)
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .set new_key 0 0 3newSTOREDappend new_key 0 0 3oldSTOREDget new_keyVALUE new_key 0 6newoldEND
Output information description:
STORED: output after successful save
NOT_STORED: this key does not exist on Memcached
CLIENT_ERROR: execution error
5.prepend instruction
The prepend directive is used to append data to the value (data value) of the existing key (key), which is the opposite of append!
The syntax is as follows:
Prepend key flags exptime bytes [noreply] value
Parameter description:
Key: is the name of the key
Flags: an integer parameter that can include a key-value pair, which can be understood as a key tag
Exptime: length of time to keep key-value pairs in the cache (in seconds, 0 means forever)
Bytes: the number of bytes stored in the cache
Noreply (optional): this parameter tells the server that there is no need to return data
Value: stored value (always on the second line)
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .set Q 00 3qqqSTOREDprepend Q 00 3wwwSTOREDget qVALUE Q 0 6wwwqqqEND
Output information description:
STORED: output after successful save
NOT_STORED: this key does not exist on Memcached
CLIENT_ERROR: execution error
6.cas instruction
The cas instruction is used to perform a "check and set" operation. It can write a value only if the value corresponding to the key has not been modified by other clients after the last value of the current client. The check is done through the cas_token parameter, which is the only 64-bit value that Memcach assigns to an element that already exists.
The syntax is as follows:
Cas key flags exptime bytes unique_cas_token [noreply] value
The parameters are described as follows:
Key: is the name of the key
Flags: an integer parameter that can include a key-value pair, which can be understood as a key tag
Exptime: length of time to keep key-value pairs in the cache (in seconds, 0 means forever)
Bytes: the number of bytes stored in the cache
A unique 64-bit value obtained by unique_cas_token through the gets command
Noreply (optional): this parameter tells the server that there is no need to return data
Value: stored value (always on the second line)
To use the CAS command on Memcached, you need to obtain the token (token) from the Memcached service provider through the gets command
The function of the gets command is similar to the basic get command. The difference between the two commands is that gets returns a little more information: the 64-bit integer value is very much like the "version" identifier of the name / value pair.
The steps of the example are as follows:
If a unique token is not set, the CAS command execution error
If the key key does not exist, execution fails
Add key-value pair
Get a unique token through the gets command
Update data using the cas command
Use the get command to see if the data is updated
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .cas tp 0900 9ERROR set tp 0900 9memcachedSTOREDgets tpVALUE tp 09 1memcachedENDcas tp 0900 5 1redisSTOREDget tpVALUE tp 0 5redisEND
Output information description:
STORED: output after successful save.
ERROR: save error or syntax error.
EXISTS: another user is also updating this data after the last value.
The key value does not exist on the NOT_FOUND:Memcached service.
2. Commonly used search instruction 1.get instruction
The get instruction gets the value (data value) stored in key (key), and returns null if key does not exist!
The syntax is as follows:
Multiple key of get key are separated by spaces, as follows: get key1 key2 key3
Parameter description:
Key: key in the key value key-value structure, which is used to find cached values
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .set lv 0 0 3lzjSTOREDget lvVALUE lv 0 3lzjEND2.gets instruction
The gets instruction gets the value (data value) with the CAS token store, or returns null if the key does not exist!
The syntax is as follows:
Multiple key of gets key are separated by spaces, as follows: gets key1 key2 key3
Parameter description:
Key: key in the key value key-value structure, which is used to find cached values
Example:
[root@localhost ~] # telnet 192.168.1.10 11211
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is'^]'.
Set lv 0 0 3
Aaa
STORED
Gets lv
VALUE lv 0 3 13
Aaa
END
/ / in the output using the gets command, the number 13 in the last column represents the CAS token whose key is lv
3.delete instruction
The delete directive is used to delete an existing key!
The syntax is as follows:
Delete key [noreply]
The parameters are described as follows:
Key: is the name of the key
Noreply (optional): this parameter tells the server that there is no need to return data
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .set qqq 0 3aaaSTOREDdelete qqqDELETEDget qqqEND
Output information description:
DELETED: deleted successfully
ERROR: syntax error or deletion failure
NOT_FOUND:key does not exist
4.incr instruction
The incr instruction is used to increment the numeric value of an existing key (key) (which must be a decimal 32-bit unsigned integer)!
The syntax is as follows:
Incr key increment_value
Parameter description:
Key: key in the key value key-value structure, which is used to find cached values
Increment_value: increased numeric value
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .set vi 0 0 210STOREDincr vi 1020get viVALUE vi 0 220END
Output information description:
NOT_FOUND:key does not exist
CLIENT_ERROR: self-increment is not an object
ERROR other errors, such as syntax errors
5.decr instruction
The decr instruction is used to self-subtract the numeric value of an existing key (key) (which must be a decimal 32-bit unsigned integer), as opposed to the incr instruction!
Syntax:
Decr key decrement_value
Parameter description:
Key: key in the key value key-value structure, which is used to find cached values
Decrement_value: reduced number
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .set vim 0 0 210STOREDdecr vim 55get vimVALUE vim 0 25 END
Output information description:
NOT_FOUND:key does not exist
CLIENT_ERROR: self-increment is not an object
ERROR other errors, such as syntax errors
6.stats instruction
The stats instruction is used to return statistics such as PID (process number), version number, number of connections, and so on.
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] '.statsSTAT pid 10527STAT uptime 4152STAT time 1576506974STAT version 1.4.33STAT libevent 2.0.22-stableSTAT pointer_size 64STAT rusage_user 1.118058STAT rusage_system 0.698786STAT curr_connections 5STAT total_connections 21STAT connection_structures 6STAT reserved_fds 20STAT cmd_get 7STAT cmd_set 19STAT cmd_flush 0STAT cmd_touch 0STAT get_hits 6STAT get_misses 1STAT get_expired 0STAT get_flushed 0STAT delete_misses 1STAT delete_hits 1STAT incr_misses 0STAT incr_hits 1STAT decr_misses 0STAT decr_hits 1STAT cas_misses 0STAT cas_badval 0STAT touch_hits 0STAT touch_misses 0STAT auth_cmds 0STAT auth_errors 0STAT bytes_read 815STAT bytes_written 459STAT limit_maxbytes 2147483648STAT accepting_conns 1STAT listen_disabled_num 0STAT time_in_listen_disabled_us 0STAT threads 4STAT conn_yields 0STAT hash_power_level 16STAT hash_bytes 524288STAT hash_is_expanding 0STAT malloc_fails 0STAT log_worker_dropped 0STAT log_worker_written 0STAT log_watcher_skipped 0STAT log_watcher_sent 0STAT bytes 648STAT curr_items 9STAT total_items 18STAT expired_unfetched 0STAT evicted_unfetched 0STAT evictions 0STAT reclaimed 0STAT crawler_reclaimed 0STAT crawler_items_checked 0STAT lrutail_reflocked 0END
Parameter explanation:
Pid: memcache server process ID
Uptime: number of seconds the server has been running
Time: the server's current Unix timestamp
Version:memcache version
Pointer_size: operating system pointer size
Rusage_user: process accumulates user time
Rusage_system: process accumulates system time
Curr_connections: current number of connections
Total number of connections since total_connections:Memcached ran
Number of connection structures assigned by connection_structures:Memcached
Number of cmd_get:get command requests
Number of cmd_set:set command requests
Number of cmd_flush:flush command requests
Number of get_hits:get command hits
Number of misses of get_misses:get command
Number of misses of delete_misses:delete command
Number of delete_hits:delete command hits
Number of misses of incr_misses:incr command
Number of incr_hits:incr command hits
Number of misses of decr_misses:decr command
Number of decr_hits:decr command hits
Number of misses of cas_misses:cas command
Cas_badval: number of times to use wipe
Auth_cmds: the number of times the authentication command was processed
Auth_errors: number of authentication failures
Bytes_read: total bytes read
Bytes_written: total bytes sent
Limit_maxbytes: total amount of memory allocated (in bytes)
Accepting_conns: whether the server has reached the maximum connection (0ram 1)
Listen_disabled_num: number of failed monitors
Threads: current number of threads
Conn_yields: number of active abortions of connection operations
Bytes: the number of bytes currently occupied by storage
Curr_items: the total number of data currently stored
Total_items: the total number of data stored since startup
Number of objects released by evictions:LRU
Reclaimed: the number of expired data entries to store new data
7.stats items instruction
The stats items instruction is used to display the number of item and storage duration in each slab (the number of seconds from the last access)
The syntax is as follows:
Stats items!
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] '.stats itemsSTAT items:1:number 9STAT items:1:age 3615STAT items:1:evicted 0STAT items:1:evicted_nonzero 0STAT items:1:evicted_time 0STAT items:1:outofmemory 0STAT items:1:tailrepairs 0STAT items:1:reclaimed 0STAT items:1:expired_unfetched 0STAT items:1:evicted_unfetched 0STAT items:1:crawler_ Reclaimed 0STAT items:1:crawler_items_checked 0STAT items:1:lrutail_reflocked 0END8.stats slabs instruction
The stats slabs instruction is used to display information about each slab, including the size, number, usage of the chunk, and so on!
The syntax is as follows:
Stats slabs
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .stats slabsSTAT 1:chunk_size 96STAT 1:chunks_per_page 10922STAT 1:total_pages 1STAT 1:total_chunks 10922STAT 1:used_chunks 9STAT 1:free_chunks 10913STAT 1:free_chunks_end 0STAT 1:mem_requested 648STAT 1:get_hits 6STAT 1:cmd_set 19STAT 1:delete_hits 1STAT 1rig incrl Hits 1STAT 1:decr_hits 1STAT 1:cas_badval 0STAT 1:touch_hits 0STAT active_slabs 1STAT total_malloced 1048512END9.stats sizes instruction
The Memcached stats sizes command is used to display the size and number of all item. This information returns two columns, the first column is the size of the item, and the second column is the number of item!
The syntax is as follows:
Stats sizes
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .stats sizes STAT 961 ENDSTAT sizes_status disabledEND10.flush_all instruction
The flush_all command, which is used to clean up all key= > value (key = > value) pairs in the cache, provides an optional parameter, time, to perform a cache cleanup operation after a specified time.
Syntax:
Flush_all [time] [noreply]
Example:
[root@localhost ~] # telnet 192.168.1.10 11211Trying 192.168.1.10...Connected to 192.168.1.10.Escape character is'^] .set lv 0 3qweSTOREDflush_allOKget lvEND
-this is the end of this article. Thank you for reading-
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.