Memcached.lua

A pure lua implementation of a simple memcached client. 1 or more memcached server(s) are currently supported. Requires the luasocket library.
See http://www.danga.com/memcached/ for more information about memcached.

memcache:set(key, value[, expiry])
Unconditionally sets a key to a given value in the memcache. The value for 'expiry' is the expiration
time (default is 0, never expire).

memcache:add(key, value[, expiry])
Like set, but only stores in memcache if the key doesn't already exist.

memcache:replace(key, value[, expiry])
Like set, but only stores in memcache if the key already exists. The opposite of add.

value = memcache:get(key)
Retrieves a key from the memcache. Returns the value or nil

values = memcache:get_multi(...)
Retrieves multiple keys from the memcache doing just one query. Returns a table of key/value pairs that were available.

memcache:delete(key)
Deletes a key. Returns true on deletion, false if the key was not found.

value = memcache:incr(key[, value])
Sends a command to the server to atomically increment the value for key by value, or by 1 if value is nil.
Returns nil if key doesn't exist on server, otherwise it returns the new value after incrementing. Value should be zero or greater.

value = memcache:decr(key[, value])
Like incr, but decrements. Unlike incr, underflow is checked and new values are capped at 0. If server value is 1, a decrement of 2 returns 0, not -1.

success = memcache:flush_all()
Runs the memcached "flush_all" command on all configured hosts, emptying all their caches.

memcache:disconnect_all()
Closes all cached sockets to all memcached servers.

memcache:set_hash(hashfunc)
Sets a custom hash function for key values. The default is a CRC32 hashing function.
'hashfunc' should be defined receiving a single string parameter and returing a single integer value.

memcache:set_encode(func)
Sets a custom encode function for serialising table values. 'func' should be defined receiving a single
table value and returning a single string value.

memcache:set_decode(func)
Sets a custom decode function for deserialising table values. 'func' should be defined receiving a
single single and returning a single table value.

memcache:enable_compression(onflag)
Turns data compression support on or off.

memcache:set_compress_threshold(size)
Set the compression threshold. If the value to be stored is larger than `size' bytes (and compression
is enabled), compress before storing.

memcache:set_compress(func)
Sets a custom data compression function. 'func' should be defined receiving a single string value and
returning a single string value.

memcache:set_decompress(func)
Sets a custom data decompression function. 'func' should be defined receiving a single string value and
returning a single string value.