Bloomd-Client
view release on metacpan or search on metacpan
my $b = Bloomd::Client->new;
my $filter = 'test_filter';
$b->create($filter);
my $array_ref = $b->list();
my $hash_ref = $b->info($filter);
$b->set($filter, 'u1');
if ($b->check($filter, 'u1')) { say "it exists!" }
my $hashref = $b->multi( $filter, qw(u1 u2 u3) );
```
Timeout support
---------------
You can set the timeout option to the constructor. The timeout will be on
reading and on writing to the socket. It can be a float, up to microseconds.
More doc
--------
Check out [the documentation on metacpan](https://metacpan.org/module/Bloomd::Client).
lib/Bloomd/Client.pm view on Meta::CPAN
has '_pid' => (is => 'ro', lazy => 1, clearer => 1, default => sub { $$ });
sub _build__socket {
my ($self) = @_;
my $socket = IO::Socket::INET->new(
Proto => $self->protocol,
PeerHost => $self->host,
PeerPort => $self->port,
Timeout => $self->timeout,
) or die "Can't connect to server: $!";
$self->timeout
or return $socket;
$Config{osname} eq 'netbsd' || $Config{osname} eq 'solaris'
and croak "the timeout option is not yet supported on NetBSD or Solaris";
my $seconds = int( $self->timeout );
my $useconds = int( 1_000_000 * ( $self->timeout - $seconds ) );
t/timeout.t view on Meta::CPAN
use Bloomd::Client;
sub create_server_with_timeout {
my $in_timeout = shift;
Test::TCP->new(
code => sub {
my $port = shift;
my $socket = IO::Socket::INET->new(
Listen => 5,
Timeout => 1,
Reuse => 1,
Blocking => 1,
LocalPort => $port
) or die "ops $!";
my $buffer;
while (1) {
my $client = $socket->accept();
if ( my $line = $client->getline() ) {
$line =~ s/$CR?$LF?$//;
# say STDERR " --- DEBUG line [$line]";
if ($in_timeout && $line ne 'info foo' ) {
sleep($in_timeout);
}
# When the client has a timeout, it'll never consume this
# print, until the Timeout of the IO::Socket::INET
$client->print('foo bar');
}
$client->close();
}
},
);
}
my $server = create_server_with_timeout(2);
( run in 0.249 second using v1.01-cache-2.11-cpan-4d50c553e7e )