NET Spy memcached using demo

Source: Internet
Author: User

Package Memcached;import Java.io.ioexception;import Java.net.inetsocketaddress;import Net.spy.memcached.memcachedclient;public class Client {private final int expiredseconds = 100;private final Inetsocketaddress Server = new Inetsocketaddress ("127.0.0.1", 10101);p rivate memcachedclient memcachedclient;public void Init () {try {memcachedclient = new memcachedclient (server);} catch (IOException e) {e.printstacktrace ();}} public void put (String key, Object obj) {memcachedclient.set (key, expiredseconds, obj);} public void Delete (String key) {memcachedclient.delete (key);} Public Object get (String key) {return memcachedclient.get (key);} public static void Main (String args[]) {Client c = new Client (), C.init (); Long begin = System.currenttimemillis (); for (int i =0;i<100;i++) {c.put (i+ "", I); System.out.println (C.get (i+ "));} System.out.println ((System.currenttimemillis ()-begin) + "MS");}}
The first is to set the expiration time. Unit is seconds, note here at the time of put. This value is a parameter of set, but assumes that the value is greater than the number of seconds in 30 days. It will be considered Unix time to set the expiration time instead of offset.

The second line is a local memcached server address and port, calling Memcacedclient to instantiate a Memcachedclient object, and the following defines the put. Get,delete can be used in a regular usage.
Direct results such as the following:
2014-08-22 09:35:01.891 INFO net.spy.memcached.MemcachedConnection:Added {QA sa=/127.0.0.1:10101, #Rops =0, #Wops = 0, # Iq=0, Toprop=null, Topwop=null, towrite=0, interested=0} to connect queue2014-08-22 09:35:01.902 WARN Net.spy.memcached.MemcachedConnection:Could not redistribute to another node, retrying primary node for 0.2014-08-22 09: 35:01.904 WARN net.spy.memcached.MemcachedConnection:Could not redistribute to another node, retrying primary node for 0 .012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 656667686970717273747576777879808182838485868788899091929394959697989992ms


NET Spy memcached using demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.