Java using memcached Simple tutorial

Source: Internet
Author: User
Tags memcached port number

  This article mainly records the basic use of memcached and simple monitor, we refer to the use of the bar

Memcached as a high concurrent memory cached system is used by many large companies, has also been using memcached project has accumulated some relevant experience. The installation of the   Install memcached is simple and is done in the following line of Ubuntu command.   Code as follows: sudo apt-get install memcached     Start is actually used, memcached need to adjust the memory size and the port number, and so on commands, then the start of the use of the following command on the line.   Code as follows: Usr/local/bin/memcached-p 11211-m 64m-d    -P Specify port number-m specify memory size-D as daemon in the background if you want to trouble Shott ING adds-VV   test test is also very simple, the installation of the official website command on the line   code as follows: Telnet localhost 11211     inside can get and set.   using in Java as the project is Java, so the Java as an example to introduce the use of Java memcached.   Java memcached A lot of clients, here to introduce the use of spymemcached   spymemcached is very simple, under the MAVEN project, we add the following dependencies.   Code as follows: <dependency>     <groupId>net.spy</groupId>     <artifactId> spymemcached</artifactid>     <version>2.9.1</version> </dependency>     So we can operate on the memcached.   Code as follows: public class Memcached {      private static memcachedclient memcached_client      static {        try {            memcached_client = new Memcachedclien T (                    addrutil.getaddresses ("localhost1:11211 localhost 2:11,211 "));        } catch (Exception e) {            SYSTEM.ERR.PRINTLN ("Cannot I NIT MEMCACHED MEMCACHED Client ");        }     {      public static void set (String key, String Value,integer Expiretime) throws Exception {        Memcached_client.set (key, expiretime, value);    }       public static String get (String key) throws Exception {        Object value = M Emcached_client.get (key);         if (null!= value)             return value.tostring ();         return null;    }  }     &NBsp Monitor we can use the following simple command to learn about the operation of Memcached, as an extension of the implementation of a simple memcached detection shell.   Code as follows: Watch "echo stats | NC 127.0.0.1 11211 "    conclusion memcached is actually easy to use and has a corresponding client on each platform."   But sometimes high concurrency may occur timeout, resulting in the buffer can not hit the situation, the specific reasons for further investigation. The author of   Memcahed recently wrote in the Go language that Groupcache is worth paying attention to.  

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.