Async-Redis

 view release on metacpan or  search on metacpan

lib/Async/Redis.pm  view on Meta::CPAN

    elsif ($type eq '*') {
        return undef unless defined $data;  # null array
        return [ map { $self->_decode_response($_) } @$data ];
    }

    return $data;
}

# Non-throwing decoder used by the unified reader. Classifies each frame
# as one of:
#   ('ok',             $decoded_value)      - normal response
#   ('redis_error',    $error_object)       - -ERR frame from Redis
#   ('protocol_error', $error_object)       - fatal desync (malformed)
sub _decode_response_result {
    my ($self, $msg) = @_;

    if (!defined $msg) {
        return ('protocol_error', Async::Redis::Error::Protocol->new(
            message => 'undef message from parser',
        ));
    }

t/01-unit/decode-response-result.t  view on Meta::CPAN


subtest 'array OK' => sub {
    my ($kind, $val) = $c->_decode_response_result({
        type => '*',
        data => [
            { type => '+', data => 'foo' },
            { type => ':', data => '7' },
        ],
    });
    is $kind, 'ok';
    is $val, ['foo', 7], 'decoded array';
};

subtest 'redis_error child inside an array is preserved as an error object element' => sub {
    my ($kind, $val) = $c->_decode_response_result({
        type => '*',
        data => [
            { type => '+', data => 'OK' },
            { type => '-', data => 'WRONGTYPE bad' },
            { type => ':', data => '42' },
        ],

t/01-unit/uri.t  view on Meta::CPAN

};

subtest 'unix socket with multiple query params' => sub {
    my $uri = Async::Redis::URI->parse('redis+unix:///run/redis.sock?db=5&timeout=10');
    is($uri->database, 5, 'database');
    # timeout would be handled by caller, not URI parser
};

subtest 'URL-encoded password' => sub {
    my $uri = Async::Redis::URI->parse('redis://:p%40ss%3Aword@localhost');
    is($uri->password, 'p@ss:word', 'password URL-decoded');
};

subtest 'URL-encoded username' => sub {
    my $uri = Async::Redis::URI->parse('redis://user%40domain:pass@localhost');
    is($uri->username, 'user@domain', 'username URL-decoded');
};

subtest 'to_hash for constructor' => sub {
    my $uri = Async::Redis::URI->parse('redis://user:pass@localhost:6380/2');
    my %hash = $uri->to_hash;

    is($hash{host}, 'localhost', 'host');
    is($hash{port}, 6380, 'port');
    is($hash{username}, 'user', 'username');
    is($hash{password}, 'pass', 'password');



( run in 1.773 second using v1.01-cache-2.11-cpan-bbb979687b5 )