memcached--perl

2011-02-17  李卓华 

1 。安装libevent, memcached, Cache::Memcached
如果说出现“error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory”, 那么执行
sudo ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5, 可以参考http://www.miotour.com/2011/01/06/memcached%E6%BA%90%E7%A0%81%E5%AE%89%E8%A3%85/

2. memcached启动:
memcached -p 11211 -m 64m -vv

3. 客户端代码:
#! /usr/bin/perl

use strict;
use warnings;
use Cache::Memcached;
my $key = 'foo';
my $value = 'bar';
my $expires = 3600;
my $memcached = Cache::Memcached->new({
servers => ['127.0.0.1:11211'],
compress_threshold => 10_000
});
$memcached->add($key, $value, $expires);
my $ret = $memcached->get($key);
print "$ret\n";

328°/3288 人阅读/0 条评论 发表评论

登录 后发表评论