目录:
- 概述
- 演示
[一]、概述
java实现了对ttserver服务端的连接和访问。相关的源代码和jar包可以到其官网下载。
官网地址:http://code.google.com/p/tokyotyrant-java/
如果是maven构建项目的,在pom.xml 的<dependencies>节点中增加如下依赖配置即可:
2 |
< groupId >tokyotyrant</ groupId >
|
3 |
< artifactId >tokyotyrant</ artifactId >
|
4 |
< version >0.11</ version >
|
7 |
< groupId >org.jboss.netty</ groupId >
|
8 |
< artifactId >netty</ artifactId >
|
9 |
< version >3.1.5.GA</ version >
|
12 |
< groupId >org.slf4j</ groupId >
|
13 |
< artifactId >slf4j-api</ artifactId >
|
14 |
< version >1.5.6</ version >
|
17 |
< groupId >org.slf4j</ groupId >
|
18 |
< artifactId >slf4j-log4j12</ artifactId >
|
19 |
< version >1.5.6</ version >
|
20 |
< scope >runtime</ scope >
|
21 |
< optional >true</ optional >
|
[二]、演示
1.RDB :官方Tokyo Tyrant API的实现
演示代码:RDBExample.java
1 |
package com.micmiu.nosql.ttserver;
|
3 |
import java.io.IOException;
|
4 |
import java.net.InetSocketAddress;
|
6 |
import tokyotyrant.RDB;
|
7 |
import tokyotyrant.transcoder.DoubleTranscoder;
|
8 |
import tokyotyrant.transcoder.IntegerTranscoder;
|
17 |
public class RDBExample {
|
19 |
public static void main(String[] args) throws IOException {
|
25 |
db.open( new InetSocketAddress( "192.168.126.134" , 1978 ));
|
30 |
if (db.put( "my_firstname" , "Sun" )) {
|
31 |
System.out.println( "db put my_firstname successful." );
|
33 |
System.out.println( "db put my_firstname error." );
|
36 |
if (db.put( "my_lastname" , "Michael" )) {
|
37 |
System.out.println( "db put my_lastname successful." );
|
39 |
System.out.println( "db put my_lastname error." );
|
42 |
if (db.put( "my_blogurl" , "www.micmiu.com" )) {
|
43 |
System.out.println( "db put my_blogurl successful." );
|
45 |
System.out.println( "db put my_blogurl error." );
|
48 |
if (db.put( "my_weibo" , "www.sina.com/ctosun" )) {
|
49 |
System.out.println( "db put my_weibo successful." );
|
51 |
System.out.println( "db put my_weibo error." );
|
55 |
value = db.get( "my_blogurl" );
|
56 |
System.out.println( "test_blogurl =: " + value);
|
58 |
value = db.get( "test_noexit" );
|
59 |
System.out.println( "test_noexit =: " + value);
|
61 |
System.out.println( "===== test repeat put " );
|
62 |
db.put( "test_desc" , "hello world" );
|
63 |
System.out.println( "test_desc =: " + db.get( "test_desc" ));
|
64 |
db.put( "test_desc" , "repeat put value is hello Michael" );
|
65 |
System.out.println( "test_desc =: " + db.get( "test_desc" ));
|
68 |
System.out.println( "===== access all key " );
|
70 |
while ((key = db.iternext()) != null ) {
|
72 |
System.out.println(key + " =: " + value);
|
74 |
System.out.println( "===== test int double " );
|
76 |
db.put( "int_i" , 3 , new IntegerTranscoder());
|
77 |
int i = db.addint( "int_i" , 4 );
|
78 |
System.out.println( " i =: " + i);
|
79 |
System.out.println( "int_i =: "
|
80 |
+ db.get( "int_i" , new IntegerTranscoder()));
|
83 |
db.put( "dou_d" , 3 .0D, new DoubleTranscoder());
|
84 |
double d = db.adddouble( "dou_d" , 4 .0D);
|
85 |
System.out.println( " d =: " + d);
|
86 |
System.out.println( "dou_d =: "
|
87 |
+ db.get( "dou_d" , new DoubleTranscoder()));
|
89 |
} catch (Exception e) {
|
运行日志如下:
db put my_firstname successful.
db put my_lastname successful.
db put my_blogurl successful.
db put my_weibo successful.
test_blogurl =: www.micmiu.com
test_noexit =: null
===== test repeat put
test_desc =: hello world
test_desc =: repeat put value is hello Michael
===== access all key
my_firstname =: Sun
my_lastname =: Michael
my_blogurl =: www.micmiu.com
my_weibo =: www.sina.com/ctosun
test_desc =: repeat put value is hello Michael
===== test int double
i =: 7
int_i =: 7
d =: 7.0
dou_d =: 7.0
2.MRDB :用于多数据源,可复制、可靠性高、响应快等特点
演示代码:MRDBExample.java
1 |
package com.micmiu.nosql.ttserver;
|
3 |
import tokyotyrant.MRDB;
|
4 |
import tokyotyrant.networking.NodeAddress;
|
13 |
public class MRDBExample {
|
19 |
public static void main(String[] args) throws Exception {
|
28 |
if (db.await(db.put( "my_firstname" , "Sun" ))) {
|
29 |
System.out.println( "MRDB put my_firstname successful." );
|
31 |
System.out.println( "MRDB put my_firstname error." );
|
34 |
if (db.await(db.put( "my_lastname" , "Michael" ))) {
|
35 |
System.out.println( "MRDB put my_lastname successful." );
|
37 |
System.out.println( "MRDB put my_lastname error." );
|
40 |
if (db.await(db.put( "my_blogurl" , "www.micmiu.com" ))) {
|
41 |
System.out.println( "MRDB put my_blogurl successful." );
|
43 |
System.out.println( "MRDB put my_blogurl error." );
|
46 |
if (db.await(db.put( "my_weibo" , "www.sina.com/ctosun" ))) {
|
47 |
System.out.println( "MRDB put my_weibo successful." );
|
49 |
System.out.println( "MRDB put my_weibo error." );
|
53 |
value = db.await(db.get( "my_blogurl" ));
|
54 |
System.out.println( "test_blogurl =: " + value);
|
56 |
value = db.await(db.get( "test_noexit" ));
|
57 |
System.out.println( "test_noexit =: " + value);
|
59 |
System.out.println( "===== test repeat put " );
|
60 |
db.put( "test_desc" , "hello world" );
|
61 |
System.out.println( "test_desc =: " + db.await(db.get( "test_desc" )));
|
62 |
db.put( "test_desc" , "repeat put value is hello Michael" );
|
63 |
System.out.println( "test_desc =: " + db.await(db.get( "test_desc" )));
|
68 |
db.put( "dou_d" , 8 .8D);
|
71 |
System.out.println( "===== access all key " );
|
73 |
.await(db.fwmkeys( "" , db.size().get().intValue()));
|
74 |
for (Object keyObj : keys) {
|
75 |
System.out.println(keyObj + " =: " + db.await(db.get(keyObj)));
|
78 |
} catch (Exception e) {
|
运行结果:
[16:42:42] INFO [tokyotyrant.networking.nio.NioNode] - Connect tcp://192.168.126.134:1978
MRDB put my_firstname successful.
MRDB put my_lastname successful.
MRDB put my_blogurl successful.
MRDB put my_weibo successful.
test_blogurl =: www.micmiu.com
test_noexit =: null
===== test repeat put
test_desc =: hello world
test_desc =: repeat put value is hello Michael
===== access all key
my_firstname =: Sun
my_lastname =: Michael
my_blogurl =: www.micmiu.com
my_weibo =: www.sina.com/ctosun
int_i =: 4
test_desc =: repeat put value is hello Michael
dou_d =: 8.8
[16:42:42] INFO [tokyotyrant.networking.nio.NioNode] - Disconnect tcp://192.168.126.134:1978
[16:42:42] INFO [tokyotyrant.networking.nio.NioNetworking] - Stopped. So will not handle IO. 0 keys will be ignored
————————
分享到:
相关推荐
然后,解压tokyotyrant-1.1.40.tar.gz文件,进入解压后的目录,运行配置脚本,指定TokyoCabinet的安装路径,编译并安装。安装完成后,启动TokyoTyrant服务器,通常通过`ttserver`命令。 4. **使用TokyoTyrant**:...
媲美memcached的缓存服务器软件包,tokyocabinet-1.4.45.tar.gz+tokyotyrant-1.1.40.tar.gz
标题 "tokyotyrant/tokyocabinet/gpac" 提及了三个关键组件:TokyoTyrant、TokyoCabinet 和 GPAC。这三者都是在IT领域中有着特定用途的工具,尤其是在数据存储和多媒体处理方面。下面将详细阐述这三个组件的知识点。...
tokyocabinet-1.4.45.tar.gz tokyotyrant-1.1.41.tar.gz tokyotyrant-0.11.jar ch-tokyocabinet-java-1.24.0.jar
首先,描述中提到的开源项目是针对.NET平台的一个C#客户端,旨在弥补.NET环境中TokyoTyrant客户端的不足。开发者在两个月前开始接触TokyoCabinet(简称TC)和TokyoTyrant(简称TT),并编写了相应的客户端代码,这个...
Tokyo Cabinet 是一个DBM的实现。这里的数据库由一系列key-value对的记录构成。key和value都可以是任意长度的字节序列,既可以是二进制也可以是字符串。这里没有数据类型和数据表的概念。 当做为Hash表数据库使用时,...
tar xvf tokyotyrant-1.1.54.tar.gz # 进入源代码目录并编译安装 cd tokyotyrant-1.1.54 ./configure make sudo make install ``` 8. **Tokyotyrant配置**: 创建一个配置文件,例如`/etc/tokyotyrant....
标题 "tokyoCabinet及tokyoTyrant简介" 指向了两个与数据库管理相关的开源工具,Tokyo Cabinet和Tokyo Tyrant。这两个工具由日本开发者开发,主要用于小型到中型的数据存储,尤其适合那些对数据读写速度有较高要求的...
在Java编程领域,`concurrentMap`是并发编程中至关重要的一部分,它提供了线程安全的映射操作。本文将深入探讨`concurrentMap`在Java内存模型(JMM,Java Memory Model)中的实现原理,以及如何通过HotCode优化并发...
在 "tokyotyrant-1.1.24" 这个压缩包中,我们预期会找到 Tokyo Tyrant 的源代码、文档、示例程序和测试用例。Tokyo Tyrant 提供了丰富的API,使得开发人员可以轻松地在各种编程语言(如C、Python、Ruby等)中与之...
从给出的信息来看,它可能是Tokyo Tyrant的一个特定版本,因为压缩包中的文件名为"tokyotyrant-1.1.41"。Tokyo Tyrant是一个轻量级、高性能的键值存储系统,常用于数据缓存和快速查找应用。 Tokyo Tyrant主要知识点...
工作线程组负责处理来自客户端的请求,每个线程都有自己的任务队列,这样可以并行处理不同的请求,提高响应速度。 ### 7. 性能对比测试 Tokyo Tyrant与MemcacheDB、Redis等其他流行数据库进行了性能对比测试。在...
- TokyoTyrant是一款由mixi工程师开发的兼容memcached协议的键值存储系统,具有更高的性能和稳定性。 - TokyoTyrant可以在某些场景下作为memcached的替代品。 综上所述,memcached作为一种强大的缓存解决方案,在...
常见的客户端有PHP、Python、Java等语言提供的库。 **1.5 使用Cache::Memcached** - **使用Cache::Memcached连接memcached**:Perl中的Cache::Memcached模块提供了与memcached服务器交互的方法。 - **保存数据**:...
- **TokyoTyrant 案例**:TokyoTyrant 是一个兼容 MemCached 协议的高性能键值存储系统。 以上内容覆盖了 MemCached 的基本概念、安装使用、内存管理、删除机制、分布式算法以及实际应用场景等方面的知识点,为深入...
- **TokyoTyrant案例**:介绍了一个兼容memcached的数据库系统TokyoTyrant,其提供了类似的功能和服务。 - **应用经验**:分享了实际应用memcached的经验教训,如通过daemontools启动服务、监控性能等。 通过以上...