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

时间: 2024-08-01 15:44:42

clj-xmemcached: memcached client for clojure的相关文章

Java Memcached Client的Benchmark——xmemcached发布1.1.1

  趁周末,做了一个java memcached client的性能benchmark,比较了4个开源的client: spymemcachehd,xmemcached,java-MemCached和岑文初的asf-cached.这个测试可能不是那么准确,为了保证命中率,无法测试更多并发下的表现,以后再测试多个memcached server下的表现可能更有价值.详细的测试报告在这里 http://xmemcached.googlecode.com/svn/trunk/benchmark/ben

Java Memcached Client Benchmark

  Xmemcached 1.2.6.1 released,所以更新了一下Java Memcached Client Benchmark.对比下Xmemached,Spymemcached和Java-Memcached-Client这三个开源客户端的性能,具体的测试信息可以看这个链接.     测试源码 svn co http://xmemcached.googlecode.com/svn/trunk/benchmark/     测试结果: svn co http://xmemcached.g

spring调用memcached client for java

转载:spring调用memcached client for java memcached client for java客户端API:memcached client for java  网址:http://www.whalin.com/memcached  调用测试类  MClient.java  Java代码   package bcndyl.test;      import org.springframework.context.ApplicationContext;   impor

分布式缓存系统Memcached简介与实践(.NET memcached client library)

原文:分布式缓存系统Memcached简介与实践(.NET memcached client library) 缘起: 在数据驱动的web开发中,经常要重复从数据库中取出相同的数据,这种重复极大的增加了数据库负载.缓存是解决这个问题的好办法.但是ASP.NET中的虽然已经可以实现对页面局部进行缓存,但还是不够灵活.此时Memcached或许是你想要的. Memcached是什么?Memcached是由Danga Interactive开发的,高性能的,分布式的内存对象缓存系统,用于在动态应用中减

clj.monitor : monitoring applications in clojure based on SSH

    My weekend project clj.monitor is beta release,it's a clojure DSL for monitoring system and applications based on SSH. Home:https://github.com/killme2008/clj.monitor An example: (ns clj.monitor.example   (:use [clj.monitor.core]         [control.

Memcached服务器安装、配置、使用详解

我使用的是CentOS 6.4系统,安装的Memcached版本为1.4.20.这里,记录一下安装配置的过程,以及如何使用一些常用的客户端来访问Memcached存储的数据. 安装配置 首先,编译.安装.配置libevent库,执行如下命令: 1 wget https://github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gz 2 tar xvzf libevent-1.4.14b-stable.tar.gz 3

memcached客户端源码分析

转载:memcached客户端源码分析 memcached的Java客户端有好几种,http://code.google.com/p/memcached/wiki/Clients 罗列了以下几种 Html代码   spymemcached          * http://www.couchbase.org/code/couchbase/java             o An improved Java API maintained by Matt Ingenthron and other

Xmemcached的FAQ和性能调整建议

  一些常见的关于xmemcached的问题,收集整理,集中解答在此.事实上这里的大部分问题都可以在用户指南里找到. 一.XMemcached是什么? 经常碰到的一个问题是很多朋友对memcached不了解,误以为xmemcached本身是一个缓存系统.Memcached是一个开源的,C写的分布式key-value缓存,XMemcached只是它的一个访问客户端.Memcached通过网络协议跟客户端交互,通过客户端你才可以去使用memcached,xmemcached是它的java客户端之一.

XMemcached的后续计划

  Xmemcached1.2.0发布到现在,从反馈来看,已经有不少用户尝试使用xmc作为他们的memcached client,并且1.2.0这个版本也比较稳定,没有发现严重的BUG.Xmemcached下一个版本是1.2.1,初步计划是在元旦左右发布,计划做出的改进如下: 1.重写所有的单元测试和集成测试,提高代码的健壮性 2.新增一些功能,如 issue 66. 3.移除deprecated方法 4.提供用户指南.    1.2.1之后初步的设想是开发1.3版本,现在xmc的最大问题是对y