[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'}."\n";
print "事件状态.";
print $event->{'state'}."\n";
$cv->send($event) });
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步