MySQL5.6.10 NoSQL API访问方式体验

WBOY
发布: 2016-06-07 16:35:16
原创
967 人浏览过

MySQL 近期发布5.6的GA版本,其中确实有很多不错的特性值得关注和尝试。NoSQL API的支持就是其中一个比较不错的亮点,我们这就来尝试一下。详细的特性介绍可访问:http://dev.mysql.com/tech-resources/articles/mysql-5.6.html 。 从MySQL官网了解到,通过M

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

从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。文档地址:http://dev.mysql.com/doc/refman/5.6/en/innodb-memcached-setup.html

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

yum install libevent
登录后复制

即可。

然后,安装libmemcached所需要的表

将插件设置成随服务启动而启动的守护插件

重启MySQL服务,安装完成。默认访问端口为11211。

下面来验证一下安装,简单的可以采用telnet的方式发送memcached命令

然后通过sql,在demo_test表中查询数据:

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

<dependency>     
      <groupid>com.googlecode.xmemcached</groupid>
      <artifactid>xmemcached</artifactid>
      <version>1.4.1</version>
</dependency>
登录后复制

代码如下:

 /**
      * @param args
      * @author lihzh(OneCoder)
      * @blog http://www.coderli.com
      * @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("10.4.44.208" , 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);
     }
登录后复制

通过mysql客户端查询记录,成功存入:

这里测试的仅仅最基本的功能,如果想使用该功能,还需要做好传统数据表与memcache表的映射关系。具体可参考:http://dev.mysql.com/doc/refman/5.6/en/innodb-memcached-developing.html。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!