Memcached connection, memcached which all key commands

https://www.runoob.com/memcached/memcached-install.html

We can specify the host and ip and port through telnet command to connect to Memcached services.

grammar

telnet HOST PORT

Command  HOST  and  PORT  is running Memcached IP and port services.

Examples

The following example demonstrates how to connect to Memcached server and perform a simple set and get commands.

Host services running Memcached present example is 127.0.0.1 (native), port 11211.

telnet 127.0.0.1 11211

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is '^]'.

set foo 0 0 3 Save command

bar data

STORED results

get foo get command

VALUE foo 0 3 data

bar data

END End of Line

quit quit

 

Why should traverse Currently, the company uses memcache and more accessible than ever. Memcache client operations generally provides only get, set and other simple operations, which are very efficient. While memcache is a key-value storage systems, but at some point, we may need to traverse the data in memcache.
How to traverse the memcache stats memcache stats command commands include:
1. stats
2. stats RESET
3. stats the malloc
4. stats Maps
5. The stats sizes
6. The stats Slabs
7. The stats items
8. The stats cachedump slab_id limit_num
9. The stats Detail [ON | off | dump]
command complete traversing through these stats command we can traverse the complete contents of memcache store, OK, let's connect to memcache via telnet directly through these commands to complete the related operations.
telnet to 192.168.15.225 (LAN test machine) of memcache server

How to traverse all the memcached inside the command keyX

 
Command execution stats items, you can see a lot of line items.
How to traverse all the memcached inside the command key
Execution stats cachedump 3 0 command. 3 a top view of the back of the items in this figure, all the display data designated 0, 1 if it is displayed only on a designated.
The following figure shows the result of performing, item string behind the key
How to traverse all the memcached inside the command key
by key listed above, we can traverse all data, here we remove a piece of data, key to Uc! ULh data.
How to traverse all the memcached inside the command key
Here, you may understand how to traverse the data of the memcache.
Paste the code to achieve the following piece of code php memcache implement traversal data, other languages can achieve their own reference code.
Paste the following code loops through the data memcache php implementation period, other languages can achieve their own reference code.
PHP:
the Java
public static Map getKeysForMap() throws UnsupportedEncodingException{ Map keylist=new HashMap(); //遍历statsItems 获取items:2:number=14 Map> statsItems=mcc.statsItems(); Map statsItems_sub=null; String statsItems_sub_key=null; int items_number=0; String server=null; //根据items:2:number=14,调用statsCacheDump,获取每个item中的key Map> statsCacheDump=null; Map statsCacheDump_sub=null; String statsCacheDumpsub_key=null; String statsCacheDumpsub_key_value=null; for (Iterator iterator=statsItems.keySet().iterator();iterator.hasNext();) { server=(String) iterator.next(); statsItems_sub=statsItems.get(server); //System.out.println(server+'==='+statsItems_sub); for (Iterator iterator_item=statsItems_sub.keySet().iterator();iterator_item.hasNext();) { statsItems_sub_key=(String) iterator_item.next(); //System.out.println(statsItems_sub_key+':=:'+bb); //items:2:number=14 if (statsItems_sub_key.toUpperCase().startsWith('items:'.toUpperCase()) && statsItems_sub_key.toUpperCase().endsWith(':number'.toUpperCase())){ items_number=Integer.parseInt(statsItems_sub.get(statsItems_sub_key).trim()); //System.out.println(statsItems_sub_key+':=:'+items_number); statsCacheDump=mcc.statsCacheDump(new String[]{server},Integer.parseInt(statsItems_sub_key.split(':')[1].trim()), items_number); for (Iterator statsCacheDump_iterator=statsCacheDump.keySet().iterator();statsCacheDump_iterator.hasNext();) { statsCacheDump_sub=statsCacheDump.get(statsCacheDump_iterator.next()); //System.out.println(statsCacheDump_sub); for (Iterator iterator_keys=statsCacheDump_sub.keySet().iterator();iterator_keys.hasNext();) { statsCacheDumpsub_key=(String) iterator_keys.next();statsCacheDumpsub_key_value = statsCacheDump_sub.get (statsCacheDumpsub_key); //System.out.println(statsCacheDumpsub_key);//key Chinese is encoded, the client is set before encoding, the server is hosted Chinese key ciphertext // System .out.println (statsCacheDumpsub_key_value); keylist.put (URLDecoder.decode (statsCacheDumpsub_key, 'UTF-8'), new KeysBean (server, Long.parseLong (statsCacheDumpsub_key_value.substring (1, statsCacheDumpsub_key_value.indexOf ( 'b;') - 1) .trim ()), Long.parseLong (statsCacheDumpsub_key_value.substring (statsCacheDumpsub_key_value.indexOf ( 'b;') + 2, statsCacheDumpsub_key_value.indexOf ( 's]') - 1) .trim ())));}} }}} return keylist;}decode(statsCacheDumpsub_key, 'UTF-8'), new KeysBean(server,Long.parseLong(statsCacheDumpsub_key_value.substring(1, statsCacheDumpsub_key_value.indexOf('b;')-1).trim()),Long.parseLong(statsCacheDumpsub_key_value.substring(statsCacheDumpsub_key_value.indexOf('b;')+2,statsCacheDumpsub_key_value.indexOf('s]')-1).trim()))); }} } } } return keylist; }decode(statsCacheDumpsub_key, 'UTF-8'), new KeysBean(server,Long.parseLong(statsCacheDumpsub_key_value.substring(1, statsCacheDumpsub_key_value.indexOf('b;')-1).trim()),Long.parseLong(statsCacheDumpsub_key_value.substring(statsCacheDumpsub_key_value.indexOf('b;')+2,statsCacheDumpsub_key_value.indexOf('s]')-1).trim()))); }} } } } return keylist; }

 

memcached possible design was time to put it positioned as a cache memory system of kv structure. So no persistent command to the disk, there is no view worth all the key commands. You may feel no need of it, if you cache a G data memory, himself a large head, dare to look. But recently, really need to see all the data values ​​Mall, and thus studied it. Also not to mention really have this command, only hidden deep only.

We still need to connect to the server now.

telnet 127.0.0.1 18887

stats items ordered as follows: Look at the previous commands article depends on the specific use. Results are as follows:

 

This tells us there are three key slot in the inside.

Continue to enter the following command:

stats cachedump 1 100  

Meaning of the parameters: The first parameter 1 represents the need to see the value of the item we see here is 1, the next figure is the first mark. item meaning our next chapter explains the memcached storage principles and methods.

The second parameter indicates how many need to see the value of the key, you can enter specific values ​​you need to see, we are here for is 100.

Execution results as shown below:

 

ok, is not very simple, very sour cool it.


 

Guess you like

Origin blog.csdn.net/BlueBirdssh/article/details/91047557