clj-xmemcached: memcached client for clojure

clj-xmemcached

Clj-xmemcachedisanopensourcememcachedclientforclojurewrappingxmemcached.Xmemcachedisanopensourcehighperformancememcachedclientforjava.

LeiningenUsage

Toincludeclj-xmemcached,add:

<code> [clj-xmemcached "0.1.1"] </code>

toyourproject.clj.

Usage

Createaclient

<!�CCode highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/�C>(use [clj-xmemcached.core])
(def client (xmemcached “host:port“))
(def client (xmemcached “host1:port1 host2:port2“ :protocol “binary“))

Thenwecreateamemcachedclientusingbinaryprotocoltotalkwithmemcachedservershost1:port1andhost2:port2.
Validoptionsincluding:

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

Storeitems

<!�C

CodehighlightingproducedbyActiproCodeHighlighter(freeware)

http://www.CodeHighlighter.com/

�C>(xsetclientkeydennis)
(xsetclient
keydennis100)
(xappendclient
keyzhuang)
(xprependclient
keyhello,)

Thevalue100istheexpiretimefortheiteminseconds.Store
functionsincludexset,xadd,xreplace,xappendandxprepend.Pleaseusedoc
toprintdocumentationforthesefunctions.

Getitems

<!�CCode highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/�C>(xget client “key“)
(xget client “key1“ “key2“ “key3“)
(xgets client “key“)

xgetsreturnsavalueincludingacasvalue,forexample:

<!�CCode highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/�C>  {:value “hello,dennis zhuang“, :class net.rubyeye.xmemcached.GetsResponse, :cas 396}

AndbulkgetreturnsaHashMapcontainsexistentitems.

Increase/Decreasenumbers

<!�C

CodehighlightingproducedbyActiproCodeHighlighter(freeware)

http://www.CodeHighlighter.com/

�C>(xincrclientnum1)
(xdecrclient
num1)
(xincrclient
num10)

Abovecodestrytoincrease/decreaseanumberinmemcachedwithkey“num”,andiftheitemisnotexists,thensetittozero.

Deleteitems

<!�CCode highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/�C>(xdelete client “num“)

Compareandset

<!�CCode highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/�C>(xcas client “key“ inc)

WeuseincfunctiontoincreasethecurrentvalueinmemcachedandtrytocompareandsetitatmostInteger.MAX_VALUEtimes.
xcascanbecalledas:

<!�CCode highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/�C> (xcas client key cas-fn max-times)

Thecas-fnisafunctiontoreturnanewvalue,setthenewvalueto

<!�CCode highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/�C>(cas-fn current-value)

Shutdown

<!�CCode highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/�C>(xshutdown client)

Flush

<!�CCode highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/�C>(xflush client)
(xflush client (InetSocketAddress. host port))

Statistics

<!�CCode highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/�C>(xstats client)

Example

Pleaseseetheexamplecodeinexample/demo.clj

License

Copyright(C)2011-2014denniszhuang[[email protected]]

DistributedundertheEclipsePublicLicense,thesameasClojure.

你可能感兴趣的:(client,create,store,items,a,clj-xmemcached)