lua 操作memcached

 1、下载 lua memcache

wget http://files.luaforge.net/releases/luamemcached/luamemcached/Version0.7/luamemcached.0.7.tar.gz

2、安装luamemcached

tar -zxvf luamemcached.0.0.tar.gz

cp ./memcached.lua /www/lua

3、例子

require"Memcached"

memcache = Memcached.Connect('10.13.0.204', 11211)

memcache:set('test1', name)

memcache:get('test1')

资源:http://luamemcached.luaforge.net/



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.

Synopsis

require('Memcached')

memcache = Memcached.Connect('some.host.com', 11000)

memcache:set('some_key', 1234)
memcache:add('new_key', 'add new value')
memcache:replace('existing_key', 'replace old value')

cached_data = memcache:get('some_key')

memcache:delete('old_key')

Methods:

memcache = Memcached.Connect()
Connect to memcached server at localhost on port number 11211.

memcache = Memcached.Connect(host[, port])
Connect to memcached server at 'host' on port number 'port'. If port is not provider, port 11211 is used.

memcache = Memcached.Connect(port)
Connect to memcached server at localhost on port number 'port'.

memcache = Memcached.Connect({{'host', port}, 'host', port})
Connect to multiple memcached servers.

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.

servers = memcache:stats([key])
Returns a table of statistical data regarding the memcache server(s). Allowed keys are:
'', 'malloc', 'sizes', 'slabs', 'items'

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.

Downloads

The latest version of LuaMemcached can be found at http://luaforge.net/projects/luamemcached/

Wiki

A Wiki with additional documentation and examples can be found here

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值