zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lee Eric <openlinuxsou...@gmail.com>
Subject Perl Client Usage
Date Tue, 21 Jul 2015 06:48:46 GMT
Hi all,

I'm trying to use ZooKeeper perl module to implement a zookeeper client.

Here are codes and output:

[root@localhost snoppy]# cat create.pl
#!/usr/bin/env perl

use warnings;
use strict;

use ZooKeeper;
use Data::Dump;

sub randstr {
my $length = shift;
my @pool = qw /0 1 2 3 4 5 6 7 8 9 q w e r t y u i o p a s d f g h j k
l z x c v b n m/;
my @result;

foreach my $item (0 .. $length - 1) {
$item = $pool[rand($#pool - 1)];
push @result, $item;
}
return join('',@result);
}

my $zk = ZooKeeper->new(hosts => 'localhost:2181');

my %value = (
value => randstr($ARGV[1]),
);

my $key = randstr($ARGV[0]);

my $path = $zk->create("/db/$key", %value);
print $path."\n";
[root@localhost snoppy]# perl create.pl 8 20
/db/t6vvoh0g

>From zookeeper end there's nothing created.

[root@localhost snoppy]# cli_st localhost:2181
Watcher SESSION_EVENT state = CONNECTED_STATE
Got a new session id: 0x14e95b8f2c41639
ls /db
time = 0 msec
/db: rc = 0
banana
orange
apple
eric
liu
vito
cai
z
watermelon
grape
time = 3 msec

Anyone has any idea about it?

Thanks.

Hui

Mime
View raw message