clj-xmemcached.core documentation

The clj-xmemcached core

*memcached-client*

->GZipCompressor

(->GZipCompressor)
Positional factory function for class clj_xmemcached.core.GZipCompressor.

->clj_json_transcoder

(->clj_json_transcoder)
Positional factory function for class clj_xmemcached.core.clj_json_transcoder.

->nippy_transcoder

(->nippy_transcoder)
Positional factory function for class clj_xmemcached.core.nippy_transcoder.

Compressor

MemcachedTranscoder

add

(add key value)(add key value expire)
Add an item with key and value,success only when item is not exists.

append

(append key value)
Append a string to an existing item's value by key

byte-array-class

bytes?

(bytes? x)

cas

(cas key cas-fn)(cas key cas-fn max-times)(cas key cas-fn max-times expire)
Compare and set an item's value by key
set the new value to:
     (cas-fn current-value)

clj-json-transcoder

compress

(compress this bs)
Compress byte array.

decompress

(decompress this bs)
Decompress byte array.

decr

(decr key__2528__auto__ delta__2529__auto__)(decr key__2528__auto__ delta__2529__auto__ init__2530__auto__)(decr key__2528__auto__ delta__2529__auto__ init__2530__auto__ expire__2531__auto__)
Decrease an item's value by key

def-transcoder

macro

(def-transcoder name & body)

default-compressor

define-incr-decr-fn

macro

(define-incr-decr-fn meta name)

define-store-fn

macro

(define-store-fn meta name)

delete

(delete key)(delete key cas)
Delete an item by key [with CAS values that was get in binary protocol].

flush-all

(flush-all)(flush-all cli)
Flush all values in memcached.WARNNING:this method will remove all items in memcached.

get

(get k)(get k1 k2)(get k1 k2 & ks)
Get items by a key or many keys,when bulk get items,the result is java.util.HashMap

get-memcached-client

(get-memcached-client)

gets

(gets key)
Gets an item's value by key,return value has a cas value

incr

(incr key__2528__auto__ delta__2529__auto__)(incr key__2528__auto__ delta__2529__auto__ init__2530__auto__)(incr key__2528__auto__ delta__2529__auto__ init__2530__auto__ expire__2531__auto__)
Increase an item's value by key

mashall

(mashall this obj)
Encode object into a byte array

memcached

(memcached servers & opts)
Create a memcached client with zero or more options(any order):
:protocol  Protocol to talk with memcached,a keyword in :text,:binary or :kestrel,default is text.
:hash  Hash algorithm,a keyword in  :consistent, :standard or :php, default is standard hash.
:pool  Connection pool size,default is 1,it's a recommended value.
:sanitize-keys  Whether to sanitize keys before operation,default is false.
:reconnect  Whether to reconnect when connections are disconnected,default is true.
:transcoder Transcoder to encode/decode data.
:session-locator memcached connection locator,default is created by :hash algorithm value.
:heartbeat  Whether to do heartbeating when connections are idle,default is true.
:timeout  Operation timeout in milliseconds,default is five seconds.
:compress-threshold Value compression threhold in bytes, default is 16K.
:name  A name to define a memcached client instance
:selector-pool-size  Reactor pool size for every client instance, it's computed based on CPUs number by default.

nippy-transcoder

no-client-error

prepend

(prepend key value)
Prepend a string to an existing item's value by key

replace

(replace key value)(replace key value expire)
Replace an existing item's value by new value

set

(set key value)(set key value expire)
Set an item with key and value.

set-client!

(set-client! client)
Set a global  memcached client for all thread contexts,prefer binding a client by `with-client` macro

shutdown

(shutdown)(shutdown cli)
Shutdown the memcached client

stats

(stats)(stats cli)
Get statistics info from all memcached servers

through

macro

(through key load)(through key expire load)
A macro to get item from cache or cache the value evaluated by load cause.
For example,you want to get the user from memcached if it is exists in cache
or load it from database to memcached and return it:

  (through uid 60
      (load-user-from-db uid)) 

touch

(touch key expire)
Touch a item with new expire time.

try-lock

macro

(try-lock key expire then)(try-lock key expire then else)
Lightweight distribution lock.
Try to lock with the global key,if gettting lock successfully,
then do something,
else do other things.For example,get the global lock to initial
in 5 seconds:

 (try-lock "init-lock" 5000
     (start-service))

unmashall

(unmashall this bs)
Decode a byte array to a object.

with-client

macro

(with-client client & body)
Evalutes body in the context of a thread-bound client to a memcached server.