Introduction to distributed cache memcached, win7 environment installation, Common commands set, get, delete, stats, memcachedwin7
Introduction to distributed cache memcached, win7 environment installation, Common commands set, get, delete, stats
1. What is memcached?
Ii. Distributed memcached non-communication
Iii. Installation Steps
4. The commands described in this article mainly include:
I,MemcachedWhat is it?
Memcached is a software developed by Brad Fitzpatric, Danga Interactive under LiveJournal. It has become an important factor in improving the scalability of Web applications among many services such as mixi, hatena, Facebook, Vox, and LiveJournal.
Many Web applications save data to RDBMS. The application server reads data from the data and displays it in the browser. However, as the data volume increases and access is concentrated, the burden on RDBMS increases, the database response deteriorates, and the website display latency.
In this case, memcached is ready to use. Memcached is a high-performance distributed memory cache server. The general purpose is to reduce the number of database accesses by caching database query results, so as to speed up dynamic Web applications and improve scalability.
II,MemcachedNon-Communication distributed
Although memcached is a "distributed" cache server, the server does not have distributed functions. Memcached does not communicate with each other to share information. So, how to implement distributed? This depends entirely on the implementation of the client.
III,Installation Steps(I have installed windows 64bit for ease of test because it is windows 7)
1. Download from the http://pan.baidu.com/s/1sk7lNgp, decompress to the specified directory, such as: C: \ Users \ Admin \ Desktop \ memcached-win64-1.4.4-14 \ memcached
2. Open the command window with cmd, go to the decompressed directory, and enter unzip memcached.exe-d install ".
3. Open the control panel and open the service. You can see that memcached is already on it. If it is not started, start it manually.
IV,The commands described in this article mainly include:
1. Storage commands)
<Command name> <key> <flags> <exptime> <bytes> [noreply] \ r \ n
Cas <key> <flags> <exptime> <bytes> <cas unique> [noreply] \ r \ n
<Command name> yes "set", "add", "replace", "append" or "prepend"
The key length cannot exceed 250 characters.
The set command is used to add a new key-value pair to the cache. If the key already exists, the previous value is replaced.
The add command adds a key-value pair to the cache only when no key exists in the cache. If a key already exists in the cache, the previous values remain the same and you will get the response NOT_STORED.
The replace command replaces the cached key only when the key already exists. If no key exists in the cache, you will receive a NOT_STORED response from the memcached server.
Append adds the data to the existing key after the existing data
Prepend Add the data to the existing key before the existing data
The append and prepend commands do not accept flags or exptime. They updated the existing data section and ignored the new flag and exptime settings.
Cas is a check and set operation, which means that the data is stored, but no one else updates it after I access the data.
<Key> used to find the cache Value
<Flags> it can include an integer parameter of a key-value pair. The client uses it to store additional information about the key-value pair.
<Exptime> the length of time for saving the key-value pair in the cache (in seconds, 0 indicates permanent)
<Bytes> bytes stored in the cache
<Cas unique> an existing 64-bit entry value. This value is returned by the client using gets.
"Noreply" is an optional parameter, and the server will not send a response.
Under this line, the data that the client sends to the server for caching.
<Data block> \ r \ n
<Data block> stored data blocks (which can be directly understood as values in the key-value structure)
Instance operation:
We can see that I saved carl to username and the result is STORED. Indicates that the storage is successful.
2. Retrieval command)
Get <key> * \ r \ n
Gets <key> * \ r \ n
<Key> * indicates one or more strings separated by spaces.
The returned result is 0 to multiple items. The stored data is displayed. The end is
"END \ r \ n"
3. Deletion)
Delete <key> [noreply] \ r \ n
<Key> is the cache key value of the server to be deleted by the client.
4. Statistics)
The stats command is used to dump the current statistics of the connected memcached instance. In the following example, the stats command displays information about the current memcached instance:
STAT pid22459 process ID
STAT uptime1027046 server running seconds
STAT timestamps 302.1662 current unix timestamp of the server
STAT version1.4.4 server version
STAT pointer_size64 OS font size (this server is 64-bit)
STAT rusage_user0.040000 cumulative user time of the process
STAT rusage_system0.260000 cumulative system time of processes
STAT curr_connections10 current number of opened connections
Total number of connections opened by STAT total_connections82
STAT connection_structures 13 Number of connection structures allocated by the server
STAT cmd_get54 total number of get commands executed
STAT cmd_set34 total number of set commands executed
STAT cmd_flush3 points to the total number of flush_all commands
STAT get_hits9 get hits
STAT get_misses45 get Miss times
STAT delete_misses5 delete miss count
STAT delete_hits1 delete hits
STAT incr_misses0 incr miss count
STAT incr_hits0 incr hits
STAT decr_misses0 decr miss count
STAT decr_hits0 decr hits
STAT cas_misses 0 cas miss count
STAT cas_hits0 cas hits
STAT cas_badval0 used for wiping times
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read15785 total number of bytes read
STAT bytes_written15222 total number of written bytes
STAT limit_maxbytes1048576 memory allocated (bytes)
STAT accepting_conns1 currently accepts connections
STAT listen_disabled_num0
STAT threads4 thread count
STAT conn_yields 0
STAT bytes0 stores item bytes
STAT curr_items0 item count
STAT total_items34 total items
STAT evictions0 indicates the total number of items deleted from the retrieved space.
5. Other commands
Flush_all this command has an optional numeric parameter. It always runs successfully, and the server sends an "OK \ r \ n" response. The effect is to immediately invalidate an existing project (default) or after the specified time. After the retrieval command is executed, NO content will be returned (unless the same key name is re-stored ). Flush_all does not immediately release the memory occupied by the project, but is executed when new projects are stored in succession (this is determined by the memcached's laziness detection and deletion mechanism ).
The result of flush_all is that all items whose Update Time is earlier than the time set by flush_all are ignored when the retrieval command is executed.
-----------------------------------------------------------------------
Http://www.memcached.org/
Github Source: https://github.com/memcached/memcached
Help document: https://github.com/memcached/memcached/blob/master/doc/protocol.txt