File: Redis.pm

package info (click to toggle)
libanyevent-redis-perl 0.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 252 kB
  • sloc: perl: 1,888; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,165 bytes parent folder | download | duplicates (5)
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
package t::Redis;
use strict;
use Test::TCP;
use Test::More;
use AnyEvent::Redis;
use FindBin;

use base qw(Exporter);
our @EXPORT = qw(test_redis);

sub test_redis(&;$) {
    my $cb = shift;
    my $args = shift;

    chomp(my $redis_server = `which redis-server`);
    unless ($redis_server && -e $redis_server && -x _) {
        plan skip_all => 'redis-server not found in your PATH';
    }

    test_tcp
        server => sub {
            my $port = shift;
            rewrite_redis_conf($port);
            exec "redis-server", "t/redis.conf";
        },
        client => sub {
            my $port = shift;
            my $r = AnyEvent::Redis->new(
                host => "127.0.0.1",
                port => $port,
                ref $args ? %$args : ()
            );
            $cb->($r, $port);
        };
}

sub rewrite_redis_conf {
    my $port = shift;
    my $dir  = $FindBin::Bin;

    open my $in, "<", "t/redis.conf.base" or die $!;
    open my $out, ">", "t/redis.conf" or die $!;

    while (<$in>) {
        s/__PORT__/$port/;
        s/__DIR__/$dir/;
        print $out $_;
    }
}

END { unlink $_ for "t/redis.conf", "t/dump.rdb" }

1;