用perl写了个memcache ping

使用方法:
[root@localhost mping]# ./m.pl 172.16.4.71:11211
ping 172.16.4.71:11211 val=Some value use(2.840ms)
ping 172.16.4.71:11211 val=Some value use(0.874ms)
ping 172.16.4.71:11211 val=Some value use(0.796ms)
ping 172.16.4.71:11211 val=Some value use(0.716ms)
ping 172.16.4.71:11211 val=Some value use(0.750ms)
ping 172.16.4.71:11211 val=Some value use(0.750ms)

如果显示 val=Some value 说明成功从memcache获取得数据

要求:perl 5.8 以上版本
需要 Cache::Memcached
http://search.cpan.org/~dormando/Cache-Memcached/

脚本如下:
#!/usr/bin/perl
use Time::HiRes qw/time/;
use Cache::Memcached;
$host = $ARGV[0];
$memd = new Cache::Memcached {
    'servers' => [$host],
    'debug' => 0,
    'compress_threshold' => 10_000,
  };


while(1){
         $start = time();
         $memd->set("my_key", "Some value");
         $val = $memd->get("my_key");
         $end = time();
         $span = 1000*($end-$start);
         printf("ping %s val=%s use(%.3fms)\n",$host,$val,$span);
         sleep(1);
}

你可能感兴趣的:(memcache)