clj-xmemcached: memcached client for clojure

简介:
  Clj-xmemcached is an opensource memcached client for clojure wrapping xmemcached. Xmemcached is an opensource high performance memcached client for java.

Leiningen Usage

To include clj-xmemcached,add:

     [clj-xmemcached "0.1.1"]

to your project.clj.

Usage

Create a client

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

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.

Store items


(xset client  " key "   " dennis " )
(xset client 
" key "   " dennis "   100 )
(xappend client 
" key "   "  zhuang " )
(xprepend client 
" key "   " hello, " )

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.

Get items

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

xgets returns a value including a cas value,for example:

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

And bulk get returns a HashMap contains existent items.

Increase/Decrease numbers


(xincr client  " num "   1 )
(xdecr client 
" num "   1 )
(xincr client 
" num "   1   0 )

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.

Delete items

(xdelete client  " num " )

Compare and set

(xcas client  " key "  inc)

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:

 (xcas client key cas - fn max - times)

The cas-fn is a function to return a new value,set the new value to

(cas - fn current - value)

Shutdown

(xshutdown client)

Flush

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

Statistics

(xstats client)

Example

Please see the example code in example/demo.clj

License

Copyright (C) 2011-2014 dennis zhuang[killme2008@gmail.com]

Distributed under the Eclipse Public License, the same as Clojure.

文章转自庄周梦蝶  ,原文发布时间2011-10-30

目录
相关文章
|
Java 关系型数据库 Ruby
|
Java 测试技术 Memcache
|
缓存 数据库 Memcache
分布式缓存系统Memcached简介与实践(.NET memcached client library)
原文:分布式缓存系统Memcached简介与实践(.NET memcached client library) 缘起: 在数据驱动的web开发中,经常要重复从数据库中取出相同的数据,这种重复极大的增加了数据库负载。
1067 0
|
算法 Java API
转:Memcached Java Client API详解
Memcached Java Client API详解 针对Memcached官方网站提供的java_memcached-release_2.0.1版本进行阅读分析,Memcached Java客户端lib库主要提供的调用类是SockIOPool和MemCachedClient?,关键类及方法整理说明如下。
887 0
|
6月前
|
Linux Memcache
Linux - 安装memcached
Linux - 安装memcached
108 0
Linux - 安装memcached