To include clj-xmemcached,add:
[clj-xmemcached "0.1.1"]
to your project.clj.
Then we create a memcached client using binary protocol to talk with memcached servers host1:port1 and host2:port2. Valid options including:
:name Client's name
:protocol Protocol to talk with memcached,a string value in text,binary or kestrel,default is text protocol.
:hash Hash algorithm,a string value in consistent or standard,default is standard hash.
:timeout Operation timeout in milliseconds,default is five seconds.
:pool Connection pool size,default is one.
The value 100 is the expire time for the item in seconds.Store functions include xset,xadd,xreplace,xappend and xprepend.Please use doc to print documentation for these functions.
xgets returns a value including a cas value,for example:
And bulk get returns a HashMap contains existent items.
Above codes try to increase/decrease a number in memcached with key "num",and if the item is not exists,then set it to zero.
We use inc function to increase the current value in memcached and try to compare and set it at most Integer.MAX_VALUE times. xcas can be called as:
The cas-fn is a function to return a new value,set the new value to
Please see the example code in example/demo.clj
Copyright (C) 2011-2014 dennis zhuang[killme2008@gmail.com]
Distributed under the Eclipse Public License, the same as Clojure.
文章转自庄周梦蝶 ,原文发布时间2011-10-30