1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#!perl
#
# This file is part of Redis
#
# This software is Copyright (c) 2015 by Pedro Melo, Damien Krotkine.
#
# This is free software, licensed under:
#
# The Artistic License 2.0 (GPL Compatible)
#
use warnings;
use strict;
use Test::More;
use Test::Fatal;
use Redis;
use lib 't/tlib';
use Test::SpawnRedisServer;
my ($c, undef, undef, undef, undef, undef, undef, undef, $sock_temp_file) = redis();
END { $c->() if $c }
my $conn = sub {
my @args = @_;
my $r;
is(
exception {
$r = Redis->new(sock => $sock_temp_file, @args);
},
undef,
'Connected to the Redis server ok',
);
return $r;
};
subtest 'basic tests' => sub {
my $r = $conn->();
ok($r->set(xpto => '42'), '... set command via UNIX ok');
is($r->get('xpto'), '42', '... and get command ok too');
is(exception { $r->quit }, undef, 'Connection closed ok');
like(exception { $r->get('xpto') }, qr!Not connected to any server!, 'Command failed ok, no reconnect',);
};
subtest 'reconnect over UNIX daemon' => sub {
my $r = $conn->(reconnect => 2);
ok($r->quit, '... and connection closed ok');
is(exception { $r->set(xpto => '43') }, undef, 'set command via UNIX ok, reconnected fine');
is($r->get('xpto'), '43', '... and get command ok too');
};
done_testing();
|