[root@wx03 zook]# cat a4.pl
use ZooKeeper;
use AnyEvent;
use AE;
use Data::Dumper;
my $zk = ZooKeeper->new(hosts => '127.0.0.1:2181');
my $stat = $zk->exists('/zk01');
if ($stat){
$zk->delete('/zk01');
}
my $created_path = $zk->create('/zk01', 'scan1000',
ephemeral => 1,
sequential => 1,
'acl' => ZOO_OPEN_ACL_UNSAFE);
###获取数据
print Dumper($zk->get("/zk01"));
###修改数据
$zk->set('/zk01' =>'scan9912472388');
print Dumper($zk->get("/zk01"));
my $cv = AE::cv;
###获取数据
my @children = $zk->get('/zk01', watcher => sub {
###事件状态
my $event = shift;
print "触发了事件.";
print $event->{'type'}."
";
print "事件状态.";
print $event->{'state'}."
";
$cv->send($event) });