get get_children方法

 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)

转载于:https://www.cnblogs.com/zhaoyangjian724/p/6199560.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值