Test::...sServer(3pm)

πŸ’– Test::RedisServer β€” the perl manpage but make it bestie πŸ’–

okay so this is Test::RedisServer(3pm) from the User Contributed Perl Documentation, and it's literally a redis-server runner for tests. that's the whole NAME section. no cap.


✨ SYNOPSIS ✨

the vibe, verbatim:

use Redis;
use Test::RedisServer;
use Test::More;

my $redis_server;
eval {
    $redis_server = Test::RedisServer->new;
} or plan skip_all => 'redis-server is required for this test';

my $redis = Redis->new( $redis_server->connect_info );

is $redis->ping, 'PONG', 'ping pong ok';

done_testing;

like, if redis-server isn't there you just skip the whole test suite and move on with your life. self-care πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

bestie. there is genuinely nothing here. the DESCRIPTION section is empty. it's giving minimalist. it's giving "the methods below speak for themselves." periodt.


πŸŽ€ METHODS πŸŽ€

🌸 new(%options)

my $redis_server = Test::RedisServer->new(%options);

creates a new redis-server instance, and β€” plot twist β€” it starts it by default. if you don't want that auto-magic, use the auto_start option, which is right down there πŸ‘‡

available options are:

  • auto_start => 0 | 1 β€” default is 1. it automatically starts the redis-server instance (that's the default behavior, bestie). you can turn this off with auto_start => 0, and then start the instance yourself, manually, with the start or exec methods below. main character energy: you decide.
  • conf => 'HashRef' β€” this is your redis.conf key value pair situation. you can use any key-value pair(s) that redis-server supports. go wild, it's your config.

if you want to use this redis.conf:

port 9999
databases 16
save 900 1

your conf parameter will be:

Test::RedisServer->new( conf => {
    port      => 9999,
    databases => 16,
    save      => '900 1',
});
  • timeout => 'Int' β€” timeout seconds for detecting if redis-server is awake or not. default is 3. it's basically the "are you up bestie??" check.
  • tmpdir => 'String' β€” temporal directory, where the redis config will be stored. by default it's created for you 🫢 but if you start Test::RedisServer via exec (e.g. with Test::TCP), you should provide it so it gets automatically deleted. your temp files deserve a clean exit too.

πŸ”₯ start

start the redis-server instance manually. you're in charge now πŸ‘‘

πŸ’œ exec

just exec to redis-server instance. this method is useful to use this module with Test::TCP, Proclet or etc. like, it's the plug-and-play option.

use File::Temp;
use Test::TCP;
my $tmp_dir = File::Temp->newdir( CLEANUP => 1 );

test_tcp(
    client => sub {
        my ($port, $server_pid) = @_;
        ...
    },
    server => sub {
        my ($port) = @_;
        my $redis = Test::RedisServer->new(
            auto_start => 0,
            conf       => { port => $port },
            tmpdir     => $tmp_dir,
        );
        $redis->exec;
    },
);

🌈 stop

stop the redis-server instance. it's the "okay bye bestie, love you, text me" of methods.

this method is automatically called from the object destructor, DESTROY. so it's already handled, you don't have to think about it, iconic behavior honestly.

πŸ“ connect_info

return connection info for the client library to connect this redis-server instance.

this parameter is designed to pass directly to the Redis module. chef's kiss, no conversion needed.

my $redis_server = Test::RedisServer->new;
my $redis = Redis->new( $redis_server->connect_info );

πŸ’€ pid

return redis-server instance's process id, or undef when redis-server is not running. so if you get undef, that server is not okay and you should check on it 😭

⭐ wait_exit

block until redis instance exited. it just sits there. patiently. waiting. like a loyal bestie outside the fitting room.


πŸ‘‘ SEE ALSO πŸ‘‘

  • Test::mysqld for mysqld.
  • Test::Memcached for Memcached.

this module steals lots of stuff from above modules. respectfully. it's inspired, not copied, we don't gatekeep ✨

  • Test::Mock::Redis, another approach for testing redis application. an alternative vibe, if you will.

🧚 INTERNAL METHODS 🧚

BUILD

DEMOLISH

these are internal. hands off, bestie. they're doing important behind-the-scenes work and they don't need your commentary πŸ™ˆ


πŸ’– AUTHOR πŸ’–

Daisuke Murase <typester@cpan.org>


Copyright (c) 2012 KAYAC Inc. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.


ngl the LICENSE file is real and you should actually read it. legal girlies stay winning.

okay that's the whole page!! this was documented with perl v5.40.1, dated 2026-01-31, and it's the Test::RedisServer(3pm) manpage β€” mwah, slay, go write some tests πŸ’…πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from