• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

MySQL5.6.10 NoSQL API访问方式体验

mysql 搞代码 4年前 (2022-01-09) 18次浏览 已收录 0个评论

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/refm本文来源gaodai#ma#com搞@代~码^网+an/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依赖:

           com.googlecode.xmemcached      xmemcached      1.4.1

代码如下:

 /**      * @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。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:MySQL5.6.10 NoSQL API访问方式体验

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址