#杂问#java中如何使用memcached?

本文详细介绍了在Java编程环境下使用Memcached的方法,包括多种Java版客户端的选择与使用,如spymemcached、Javamemcachedclient等,并讨论了如何通过通讯协议提升性能。同时,提供了关于Memcached在不同场景下的应用策略与优化建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如何使用memcached,当java编程的时候?

1.使用java版的客户端

参考官方文档 http://code.google.com/p/memcached/wiki/Clients#Java

包括如下多种客户端可以选择

1.1spymemcached

http://www.couchbase.org/code/couchbase/java

“ An improved Java API maintained by Matt Ingenthron and others at Couchbase. Aggressively optimised, ability to run async, supports binary protocol, support Membase and Couchbase features, etc. See site for details. ”
针对异步进行优化,支持二进制协议,支持membase和couchbase特性。

由Matt Ingenthron 等维护的Java API。

1.2Java memcached client

 http://www.whalin.com/memcached
 “A Java API is maintained by Greg Whalin from Meetup.com. ”
由Greg Whalin维护的Java API。

最新版本2.6.0下载地址: http://code.google.com/p/spymemcached/downloads/detail?name=memcached-2.6.jar&can=2&q=

1.3其他客户端

javamemcachedclient    http://code.google.com/p/javamemcachedclient

“ManyBrain Java Memcached client built for speed and high-scalability. Takes significant advantage of multi-core systems. Peak performance on loopback network at about number_of_threads = number_of_cores+2 (highly approximate). Throughput loss is gradual tested up to 500 threads. For real networks (with notably more latency than loopback) a few thousand threads should perform well (of course use, -Xss96k or so)

Very high performance for string and small payloads because of streamlined code. Large payloads (i.e., big hashmaps) still benefit, but less so as the Java serialization mechanism is a serious bottleneck.

This API is BETA and is not feature complete (yet). Notably, CAS is not supported. ”

好像很厉害的速度、高扩展特性。

memcache-client-forjava     http://code.google.com/p/memcache-client-forjava

“当前最新版本为2.5.2。svn代码已经上传,有需要的同学可以直接下载使用maven来构建项目。

该项目是Memcache Java 客户端的实现

使用前先请下载帮助文档:在downloads中Memcached Client HandBook(特别注意对于第三方开源库版本依赖)

具体的代码,文档,测试内容都在Downloads 中可以获得

《MemCached Cache Java 客户端优化历程.doc》将描述详细的封装和优化过程

有任何问题可以联系wenchu.cenwc@alibaba-inc.com ”

xmemcached    http://code.google.com/p/xmemcached 
XMemcached is a high performance, easy to use multithreaded memcached client injava.

It's nio based and was carefully turned to get top performance.

Xmemcached 1.4.1 has been released! Please check ReleaseNotes.

高性能的多线程memcached客户端。


1.4Integrations

simple-spring-memcached    http://code.google.com/p/simple-spring-memcached

“Distributed caching can be a big, hairy, intricate, and complex proposition when using it extensively.
Simple Spring Memcached (SSM) attempts to simplify implementation for several basic use cases.”

memcached-session-manager    http://code.google.com/p/memcached-session-manager 

“A tomcat high-availability solution that additionally stores sessions in amemcached compatible key-value store for session failover, while reading them from local memory for optimal performance (for sticky sessions). For non-sticky sessions the memcached compatible backend is used as session store (keeping a copy of the session in a secondary memcached node). "memcached compatible" here refers to the memcached protocol, therefore the backend can be any (if you like persistent) solution "speaking" memcached (e.g.memcachedb,membase etc.). ”

2.使用通讯协议

参考官方问文档 http://code.google.com/p/memcached/wiki/NewProtocols

包括 text protocol 和 binary protocol


2013年7月2日18:49:34待续

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值