Skip to content

echou/memcached-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An efficient memcached client that simply wraps around libmemcached.

Requirement

libmemcached 1.0+ should be installed. OTP should be R15B or above.

Build

./rebar compile

a memcached_drv.so is created under priv/lib.

Usage

start the application

mcache:start(). 

  or

application:start(mcache).

get

mcache:get(Prefix, Key)

fetches <Prefix>:<Key> from memcached.

  • Prefix and Key can be atom, string, binary, list or tuple. tuple/list items are separated by ":".
  • returns undefined if not found.
  • unbox to correct format according to the type it was set. (see mcache:set)

set

mcache:set(Prefix, Key, Value, Type, Timeout)
  • Prefix and Key can be atom, list, binary, iolist or integer.
  • Value: depends on Type, can be binary, iolist, int or erlang term.
  • Type: can be one of raw (binary), native (erlang term, saved in term_to_binary format), int (an integer).
  • Timeout: can be one of default (default expiration: 300 seconds), infinity, {X, seconds}, {X, minutes}, {X, hours}, {X, days}, or an integer (as is).

Note 1: no reply is returned for best performance.
Note 2: Type is encoded as memcached protocol field flags: 0 - raw, 100 - native, 103 - int.

delete

mcache:delete(Prefix, Key)

Configuration

pools

{pools,  % defines several pools
 	[{name,generic}, % pool name
 	 {connection_count,10},
 	 {servers,[{"127.0.0.1:11211",255},{"192.168.1.1:11211",255}]}] % servers and weights
 	% another pool definition, ....
}

expires

{expires, 
  [ {prefix1, {PoolName, Timeout1}},
    {prefix2, {PoolName, Timeout2}} ]
}
  • PoolName: is one of the pool names from pools definitions.
  • Timeout: sees the timeout definition of mcache:set function.

About

an Erlang memcached client application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published