get 方法:
[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('/zk/child600');
if ($stat){
$zk->delete('/zk/child600');
}
my $created_path = $zk->create('/zk/child600', 'child600',
ephemeral => 1,
sequential => 1,
'acl' => ZOO_OPEN_ACL_UNSAFE);
###获取数据
my ($data,$stat)=$zk->get('/zk');
print $data;
[root@wx03 zook]# perl a4.pl
Odd number of elements in hash assignment at /usr/local/perl/lib/site_perl/5.22.1/x86_64-linux/ZooKeeper.pm line 392.
myData[root@wx03 zook]#
get_child 方法:
my $zk = ZooKeeper->new(hosts => '127.0.0.1:2181');
my $stat = $zk->exists('/zk/child600');
if ($stat){
$zk->delete('/zk/child600');
}
my $created_path = $zk->create('/zk/child600', 'child600',
ephemeral => 1,
sequential => 1,
'acl' => ZOO_OPEN_ACL_UNSAFE);
###获取数据
my (@data,$stat)=$zk->get_children('/zk');
foreach (@data){
print "\$_ is $_\n";
};
[root@wx03 zook]# perl a4.pl
Odd number of elements in hash assignment at /usr/local/perl/lib/site_perl/5.22.1/x86_64-linux/ZooKeeper.pm line 392.
$_ is child500
$_ is child700
$_ is child600
$_ is test
$_ is child300
$_ is child1
$_ is child200
获取child 子节点的值:
[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('/zk/child600');
if ($stat){
$zk->delete('/zk/child600');
}
my $created_path = $zk->create('/zk/child600', 'child600',
ephemeral => 1,
sequential => 1,
'acl' => ZOO_OPEN_ACL_UNSAFE);
###获取数据
my (@data,$stat)=$zk->get_children('/zk');
foreach (@data){
print "\$_ is $_\n";
print $zk->get("/zk/$_");
print "\n";
};
[root@wx03 zook]# perl a4.pl
Odd number of elements in hash assignment at /usr/local/perl/lib/site_perl/5.22.1/x86_64-linux/ZooKeeper.pm line 392.
$_ is test2
d4rwrHASH(0x14d0e28)
$_ is child600
HASH(0x14e5f38)
$_ is test
aaaHASH(0x14e5f38)
$_ is test1
dadadHASH(0x14e5f38)