- 浏览: 69464 次
- 性别:
- 来自: 北京
-
文章分类
- 全部博客 (121)
- luence (7)
- MoveLuceneRebuild (0)
- ehcache (0)
- memcached (12)
- WeiXin (1)
- hy (0)
- alipay (0)
- Wxap (0)
- 学习笔记 (14)
- java generic (1)
- threadpool (0)
- Awmazon (0)
- com.yulong.businessCache (0)
- com.yulong.util (1)
- com.wxap (0)
- com.yulong.wxshop (0)
- com.alipay (0)
- com.yulong.session (0)
- com.yulong.handler (0)
- kafka (0)
- http://www.cnblogs.com/oubo/archive/2012/02/04/2394646.html (0)
- redis (0)
- MongoDB (2)
- Nginx (1)
- java (10)
- 云搜索 (4)
- Hadoop (1)
- Spring (15)
- Thread (1)
- 博客链接 (0)
- AJAX与CSS (7)
- 项目管理 (1)
- restful架构 (1)
- 多线程 (3)
- Java面试 (6)
- 牛人博客 (2)
- Linux (1)
- java集合 (1)
- Socket与Nio (1)
- SQL开发 (2)
- Spring Boot (3)
- Spring4.1 (4)
- tomcat配置 (1)
- JVM (5)
- Hibernate (1)
- Dubbo (7)
- MQ (2)
- java常见错误 (0)
最新评论
/**
* Copyright (c) 2008 Greg Whalin
* All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the BSD license
*
* This library is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE.
*
* You should have received a copy of the BSD License along with this
* library.
*
* @author greg whalin <greg@meetup.com>
*/
package com.meetup.memcached.test;
import org.apache.log4j.BasicConfigurator;
import com.yulong.memcached.MemcachedClient;
import com.yulong.memcached.SockIOPool;
public class TestMemcached {
public static void main(String[] args) {
// memcached should be running on port 11211 but NOT on 11212
BasicConfigurator.configure();
String[] servers = { "10.1.21.27:11211,10.1.21.28:11211,10.1.21.29:11211" };
SockIOPool pool = SockIOPool.getInstance();
pool.setServers( servers );
pool.setFailover( true );
pool.setInitConn( 10 );
pool.setMinConn( 5 );
pool.setMaxConn( 250 );
pool.setMaintSleep( 30 );
pool.setNagle( false );
pool.setSocketTO( 3000 );
pool.setAliveCheck( true );
pool.initialize();
MemcachedClient mcc = new MemcachedClient();
// turn off most memcached client logging:
// com.meetup.memcached.Logger.getLogger( MemcachedClient.class.getName() ).setLevel( com.meetup.memcached.Logger.LEVEL_WARN );
for ( int i = 0; i < 10; i++ ) {
boolean success = mcc.set( "" + i, "Hello!" );
String result = (String)mcc.get( "" + i );
System.out.println( String.format( "set( %d ): %s", i, success ) );
System.out.println( String.format( "get( %d ): %s", i, result ) );
}
System.out.println( "\n\t -- sleeping --\n" );
try { Thread.sleep( 10000 ); } catch ( Exception ex ) { }
for ( int i = 0; i < 10; i++ ) {
boolean success = mcc.set( "" + i, "Hello!" );
String result = (String)mcc.get( "" + i );
System.out.println( String.format( "set( %d ): %s", i, success ) );
System.out.println( String.format( "get( %d ): %s", i, result ) );
}
}
}
* Copyright (c) 2008 Greg Whalin
* All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the BSD license
*
* This library is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE.
*
* You should have received a copy of the BSD License along with this
* library.
*
* @author greg whalin <greg@meetup.com>
*/
package com.meetup.memcached.test;
import org.apache.log4j.BasicConfigurator;
import com.yulong.memcached.MemcachedClient;
import com.yulong.memcached.SockIOPool;
public class TestMemcached {
public static void main(String[] args) {
// memcached should be running on port 11211 but NOT on 11212
BasicConfigurator.configure();
String[] servers = { "10.1.21.27:11211,10.1.21.28:11211,10.1.21.29:11211" };
SockIOPool pool = SockIOPool.getInstance();
pool.setServers( servers );
pool.setFailover( true );
pool.setInitConn( 10 );
pool.setMinConn( 5 );
pool.setMaxConn( 250 );
pool.setMaintSleep( 30 );
pool.setNagle( false );
pool.setSocketTO( 3000 );
pool.setAliveCheck( true );
pool.initialize();
MemcachedClient mcc = new MemcachedClient();
// turn off most memcached client logging:
// com.meetup.memcached.Logger.getLogger( MemcachedClient.class.getName() ).setLevel( com.meetup.memcached.Logger.LEVEL_WARN );
for ( int i = 0; i < 10; i++ ) {
boolean success = mcc.set( "" + i, "Hello!" );
String result = (String)mcc.get( "" + i );
System.out.println( String.format( "set( %d ): %s", i, success ) );
System.out.println( String.format( "get( %d ): %s", i, result ) );
}
System.out.println( "\n\t -- sleeping --\n" );
try { Thread.sleep( 10000 ); } catch ( Exception ex ) { }
for ( int i = 0; i < 10; i++ ) {
boolean success = mcc.set( "" + i, "Hello!" );
String result = (String)mcc.get( "" + i );
System.out.println( String.format( "set( %d ): %s", i, success ) );
System.out.println( String.format( "get( %d ): %s", i, result ) );
}
}
}
发表评论
-
Memcached处理
2015-07-21 14:00 362Memcached有两个核心 ... -
memcached工作原理与优化建议
2015-01-07 10:30 330工作原理 基本概念:slab,page,chunk。 ... -
MemcachedTest
2014-11-10 09:08 320/** * Copyright (c) 2008 Greg ... -
MemcachedBench
2014-11-10 09:09 382/** * Copyright (c) 2008 Greg ... -
MemcachedService
2014-11-10 09:10 457package com.yulong.memcached.se ... -
TestDropMemcacheUser
2014-11-10 09:10 477package com.yulong.memcached; ... -
TestAddMemcacheMemberAddress
2014-11-12 09:23 233package com.yulong.memcached; ... -
SockIOPool
2014-11-12 09:24 1441/** * Copyright (c) 2008 Greg ... -
NestedIOException
2014-11-12 09:24 803/** * Copyright (c) 2008 Greg ... -
NativeHandler
2014-11-12 09:24 281/** * Copyright (c) 2008 Greg ... -
MemcachedClient
2014-11-12 09:24 1812/** * Copyright (c) 2008 Greg ... -
MccErrorHandler
2014-11-07 22:10 0package com.yulong.memcached; ... -
Logger
2014-11-07 22:10 0/** * Copyright (c) 2008 Greg ... -
LineInputStream
2014-11-07 22:10 0/** * Copyright (c) 2008 Greg ... -
ErrorHandler
2014-11-07 22:09 0/** * Copyright (c) 2008 Greg ... -
ContextObjectInputStream
2014-11-07 22:09 0/** * Copyright (c) 2008 Greg ... -
ByteBufArrayInputStream
2014-11-07 22:08 0/** * Copyright (c) 2008 Greg ... -
MemberInfoMemcachedService
2014-11-07 17:55 0package com.yulong.memcached.se ... -
GrabMemcachedService
2014-11-07 17:50 0package com.yulong.memcached.se ...
相关推荐
通过理解和实践"TestMemcached.java",你可以更好地掌握如何在实际项目中利用Memcached来优化数据访问和提高应用性能。记住,关键在于理解Memcached的工作原理,以及如何有效地利用它来提升系统的整体效率。
在提供的`testMemcached`文件中,我们可以预期它包含了一系列用于测试上述功能的代码,例如单元测试用例或集成测试脚本。通过运行这些测试,开发者可以全面地了解他们的Memcached部署是否满足需求,并进行必要的调整...
9. **压缩包子文件`TestMemcached`**: 这可能是包含Java测试类的源代码文件,其中包含了连接和操作Memcached的逻辑。分析这个文件可以帮助理解实际的测试实现和代码结构。 总结来说,"普通java工程测试连接...
public class TestMemcached { public static void main(String[] args) { MemcachedUtils.set("testKey", "testValue", 60); // 存储键值对,过期时间为60秒 Object value = MemcachedUtils.get("testKey"); //...
使用JUnit或其他测试框架,创建一个测试类,如`TestMemcached`,包含上述操作的测试用例。 5. **异常处理**:在实际应用中,应适当地处理可能抛出的异常,如`ConnectException`、`TimeoutException`等,以确保系统...
public void testMemcached() { // 使用 memcachedClient 对象进行缓存操作 } } ``` 通过以上步骤,我们可以成功地将 Memcached 集成到 Spring Boot 项目中,从而提高应用程序的性能和响应速度。