Memcontinuationed Memcached的Scala客户端开源项目

我要开发同款
匿名用户2013年02月03日
42阅读
开发技术Scala
所属分类数据库驱动程序、数据库相关
授权协议Apache

作品详情

Memcontinuationed是Scala的异步memcached客户端。Memcontinuationed是JVM上最快的Memcached客户端,比spymemcached或 Whalin的客户端要快得多。

示例代码:

importcom.dongxiguo.memcontinuationed.Memcontinuationedimportcom.dongxiguo.memcontinuationed.StorageAccessorimportjava.io._importjava.net._importjava.nio.channels.AsynchronousChannelGroupimportjava.util.concurrent.Executorsimportscala.util.continuations.resetimportscala.util.control.Exception.CatcherobjectSample{ defmain(args:Array[String]){  valthreadPool=Executors.newCachedThreadPool()  valchannelGroup=AsynchronousChannelGroup.withThreadPool(threadPool)  //Thelocatordecidewherethememcachedserveris.  //Youmaywanttoimplementketamahashinghere.  deflocator(accessor:StorageAccessor[_])={   newInetSocketAddress("localhost",1978)  }  valmemcontinuationed=newMemcontinuationed(channelGroup,locator)  //Theerrorhandler  implicitdefcatcher:Catcher[Unit]={   casee:Exception=>    scala.Console.err.print(e)    sys.exit(-1)  }  reset{   memcontinuationed.set(MyKey("hello"),"Hello,World!")   valresult=memcontinuationed.require(MyKey("hello"))   assert(result=="Hello,World!")   println(result)   sys.exit()  } }}/** *`MyKey`specifieshowtoserializethedataofkey/valuepair. */caseclassMyKey(overridevalkey:String)extendsStorageAccessor[String]{ overridedefencode(output:OutputStream,data:String,flags:Int){  output.write(data.getBytes("UTF-8")) } overridedefdecode(input:InputStream,flags:Int):String={  valresult=newArray[Byte](input.available)  input.read(result)  newString(result,"UTF-8") }}

 

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论