MySQL5.6.10 NoSQL API访问方式体验

MySQL 近期发布5.6的GA版本,其中确实有很多不错的特性值得关注和尝试。NoSQL API的支持就是其中一个比较不错的亮点,我们这就来尝试一下。详细的特性介绍可访问:

从MySQL官网了解到,通过Memcache的API即可访问MySQL的NoSQL API。

Many of the latest generation of web, cloud, social and mobile applications require fast operations against simple Key/Value pairs. At the same time, they must retain the ability to run complex queries against the same data, as well as ensure the data is protected with ACID guarantees. With the new NoSQL API for InnoDB, developers have all the benefits of a transactional RDBMS, coupled with the performance capabilities of Key/Value store.
MySQL 5.6 provides simple, key-value interaction with InnoDB data via the familiar Memcached API. Implemented via a new Memcached daemon plug-in to mysqld, the new Memcached protocol is mapped directly to the native InnoDB API and enables developers to use existing Memcached clients to bypass the expense of query parsing and go directly to InnoDB data for lookups and transactional compliant updates. The API makes it possible to re-use standard Memcached libraries and clients, while extending Memcached functionality by integrating a persistent, crash-safe, transactional database back-end. The implementation is shown here:

So does this option provide a performance benefit over SQL? Internal performance benchmarks using a customized Java application and test harness show some very promising results with a 9X improvement in overall throughput for SET/INSERT operations:

首先部署Server端的Memcache plugin集成环境。目前支持的系统为Linux, Solaris, and OS X,不支持windows。文档地址:

由于我采用的tar包安装的MySQL,所以在安装memcache plugin的时候需要先安装libevent包。

yum install libevent







再通过Java代码操作一下,我们采用xmemcached作为client api。官方地址:。Maven依赖:

<dependency >     
      <groupId >com.googlecode.xmemcached</groupId >
      <artifactId >xmemcached</artifactId >
      <version >1.4.1</version >
</dependency >


      * @param args
      * @author lihzh(OneCoder)
      * @blog
      * @throws MemcachedException
      * @throws InterruptedException
      * @throws TimeoutException
      * @throws IOException
      * @date 2013 -3 -12 下午12:07:41
     public static void main(String[] args) throws TimeoutException, InterruptedException, MemcachedException, IOException {
           MemcachedClient client = new XMemcachedClient("" , 11211);
            // store a value for one hour(synchronously).
           client.set( "key", 3600, "onecoder");
            // Retrieve a value.(synchronously).
           Object someObject = client.get( "key");
            // Retrieve a value.(synchronously),operation timeout two seconds.
           someObject = client.get( "key", 2000);
           System. out.println(someObject);



Thanks a lot.