isanopensourcememcachedclientforclojurewrapping.isanopensourcehighperformancememcachedclientforjava.

LeiningenUsage

Toincludeclj-xmemcached,add:

 [clj-xmemcached "0.1.1"] 

toyourproject.clj.

Usage

Createaclient

(use [clj-xmemcached.core])(def client (xmemcached “host:port“))(def client (xmemcached “host1:port1 host2:port2“ :protocol “binary“))

Thenwecreateamemcachedclientusingbinaryprotocoltotalkwithmemcachedservershost1:port1andhost2:port2.

Validoptionsincluding:

 :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. 

Storeitems

CodehighlightingproducedbyActiproCodeHighlighter(freeware)

http://www.CodeHighlighter.com/

–>(xsetclientkeydennis)

(xsetclientkeydennis100)
(xappendclient
keyzhuang)
(xprependclient
keyhello,)

Thevalue100istheexpiretimefortheiteminseconds.Store

functionsincludexset,xadd,xreplace,xappendandxprepend.Pleaseusedoc
toprintdocumentationforthesefunctions.

Getitems

(xget client “key“)(xget client “key1“ “key2“ “key3“)(xgets client “key“)

xgetsreturnsavalueincludingacasvalue,forexample:

{:value “hello,dennis zhuang“, :class net.rubyeye.xmemcached.GetsResponse, :cas 396}

AndbulkgetreturnsaHashMapcontainsexistentitems.

Increase/Decreasenumbers

CodehighlightingproducedbyActiproCodeHighlighter(freeware)

http://www.CodeHighlighter.com/

–>(xincrclientnum1)

(xdecrclientnum1)
(xincrclient
num10)

Abovecodestrytoincrease/decreaseanumberinmemcachedwithkey“num”,andiftheitemisnotexists,thensetittozero.

Deleteitems

(xdelete client “num“)

Compareandset

(xcas client “key“ inc)

WeuseincfunctiontoincreasethecurrentvalueinmemcachedandtrytocompareandsetitatmostInteger.MAX_VALUEtimes.

xcascanbecalledas:

(xcas client key cas-fn max-times)

Thecas-fnisafunctiontoreturnanewvalue,setthenewvalueto

(cas-fn current-value)

Shutdown

(xshutdown client)

Flush

(xflush client)(xflush client (InetSocketAddress. host port))

Statistics

(xstats client)

Example

Pleaseseetheexamplecodein

License

Copyright(C)2011-2014denniszhuang[]

DistributedundertheEclipsePublicLicense,thesameasClojure.