這大體上可以看出,服務器端口緩存技術。
memcached 官方:http://www.danga.com/memcached/
安裝前,先安裝 libevent
其上為 linux 軟件一般安裝,看他們readme文檔
$>memcached -d -u nobody -m 512 127.0.0.1 -p 11211
如果有異常,
ln -s /usr/local/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2
參考 http://blog.chinaunix.net/u2/70049/showart_1665279.html
我這就使用 perl 語言了,
其他語言參考 http://code.google.com/p/memcached/wiki/Clients
perl 使用 cpan> install Cache::Memcached ;#會使用 perl 我就不說了
代碼說明:不停對 key 為test 的值進行遞增
#!/bin/perl -w
use Cache::Memcached;
my $memd = new Cache::Memcached{servers => ['127.0.0.1:11211'] };
my $key = 'test';
$memd->add($key => 1,3600) or warn 'Alread added';
while(1){
print $memd->get($key),"\n";
$memd->incr($key) or warn 'FAIL!';
}
use Cache::Memcached;
my $memd = new Cache::Memcached{servers => ['127.0.0.1:11211'] };
my $key = 'test';
$memd->add($key => 1,3600) or warn 'Alread added';
while(1){
print $memd->get($key),"\n";
$memd->incr($key) or warn 'FAIL!';
}
使用 telnet 127.0.0.1 11211
$> get test
VALUE test 0 2
97 #這就是我們遞增的值,當然你使用什么語言取都是一樣的
END
整理 www.aygfsteel.com/Good-Game