Test::...::Redis(3pm)

πŸ“¦
version 0.22 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Test::...::Redis(3pm) πŸ’–

okay bestie, so this is a User Contributed Perl Documentation page for Test::Mock::Redis β€” the fake-Redis-for-testing module you've been looking for. it's a .3pm manpage, meaning it's Perl module docs, and we're gonna walk it all the way through. grab a boba, we're going in πŸ§‹βœ¨


✨ NAME ✨

Test::Mock::Redis β€” use this in place of Redis for unit testing 🫢

🌸 VERSION 🌸

Version 0.22 β€” that's the one, bestie.

πŸ¦‹ SYNOPSIS πŸ¦‹

so the whole point: Test::Mock::Redis can be used in place of Redis for running tests without needing a running redis instance. no server, no daemon, no tears. πŸ˜­πŸ’–

use Test::Mock::Redis;

my $redis = Test::Mock::Redis->new(server => 'whatever');

$redis->set($key, 'some value');

$redis->get($key);

...

this module is designed to function as a drop in replacement for Redis.pm for testing purposes. periodt. πŸ‘‘

check perldoc Redis and the redis documentation at <http://redis.io> for the real deal, iykyk.


πŸŽ€ PERSISTENCE πŸŽ€

okay this part is lowkey iconic. the "connection" to the mocked server (and its stored data) will persist beyond the object instance, just like a real Redis server. πŸ’…

that means you do not need to save the instance to this object in order to preserve your data. simply call new with the same server parameter and the same instance will be returned, with all data preserved. no cap. 🧚

it's giving "the server never left, you did." πŸ’€βœ¨

πŸ’œ SUBROUTINES/METHODS πŸ’œ

🌈 new 🌈

Create a new Test::Mock::Redis object.

It can be used in place of a Redis object for unit testing.

It accepts the server argument, just like Redis.pm's new.

🌈 num_databases 🌈

Redis ships with a default of 16 databases, and that's what this module handles by default. if you need to change that, do:

use Test::Mock::Redis num_databases => 21;

or at run-time:

Test::Mock::Redis::change_num_databases(21);

⭐ PIPELINING ⭐

See "PIPELINING" in Redis β€” most methods support the use of a callback sub as the final argument. 🫢

for this implementation specifically: the callback sub will be called immediately (before the result of the original method is returned), and wait_all_responses does nothing. also, combining pipelining with multi/exec is not supported. so don't. πŸ™ˆ


πŸ’€ TODO πŸ’€

Lots! 😭 bestie we are so honest here.

  • Not all Redis functionality is implemented. The test files that output TODO are still to be done.
  • The top of all test files [except 01-basic.t] has the list of commands tested or to-be tested in the file.

so here's the little legend, it's giving grade-school report card:

  • those marked with an x are pretty well-tested.
  • those marked with an o need help. πŸ₯Ί
  • those that are unmarked have no tests, or are un-implemented.

for example:

x   AUTH          <--- has some tests

o   KEYS          <--- only partially tested and/or implemented

    ZINTERSTORE   <--- not tested (or maybe not implemented)

beyond that, it would be neat to add methods to inspect how often keys were accessed and get other information that allows the module user to confirm that their code interacted with redis (or Test::Mock::Redis) as they expected. future plans, slay. ✨


🫢 AUTHOR 🫢

Jeff Lavallee, "<jeff at zeroclue.com>"

πŸ‘‘ SEE ALSO πŸ‘‘

The real Redis.pm client whose interface this module mimics: <http://search.cpan.org/dist/Redis>

πŸ”₯ BUGS πŸ”₯

Please report any bugs or feature requests to "bug-mock-redis at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Mock-Redis>.

the author will be notified, and then you'll automatically be notified of progress on your bug as changes get made. so like, a little notification chain. cute. πŸ’Œ

🌸 SUPPORT 🌸

You can find documentation for this module with the perldoc command.

perldoc Test::Mock::Redis

You can also look for information at:

  • RT: CPAN's request tracker

<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Mock-Redis>

  • AnnoCPAN: Annotated CPAN documentation

<http://annocpan.org/dist/Test-Mock-Redis>

  • CPAN Ratings

<http://cpanratings.perl.org/d/Test-Mock-Redis>

  • Search CPAN

<http://search.cpan.org/dist/Test-Mock-Redis/>


πŸ’– ACKNOWLEDGEMENTS πŸ’–

Salvatore Sanfilippo for redis, of course! πŸ™

Dobrica Pavlinusic & Pedro Melo for Redis.pm

The following people have contributed to Test::Mock::Redis:

  • Chris Reinhardt
  • Ian Burrell
  • Gianni Ceccarelli
  • Karen Etheridge
  • Keith Broughton
  • Kevin Goess
  • Neil Bowers
  • Nigel Gregoire
  • Thomas Bloor
  • Valery Kalesnik
  • Yaakov Shaul

the whole group chat showed up. legends, every one. πŸ‘‘βœ¨


Copyright 2018 Jeff Lavallee.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See <http://dev.perl.org/licenses/> for more information.


and that's a wrap, bestie 🫢 this lil page came to you via perl v5.36.0, dated 2022-10-16, and it's filed under Test::...::Redis(3pm). go forth and mock responsibly πŸ’…πŸ’–
πŸ“¦ where this page comes from