Actions Status MetaCPAN Release

NAME

Redis::Namespace - a wrapper of Redis.pm that namespaces all Redis calls

SYNOPSIS

use Redis;
use Redis::Namespace;

my $redis = Redis->new;
my $ns = Redis::Namespace->new(redis => $redis, namespace => 'fugu');

$ns->set('foo', 'bar');
# will call $redis->set('fugu:foo', 'bar');

my $foo = $ns->get('foo');
# will call $redis->get('fugu:foo');

DESCRIPTION

Redis::Namespace is a wrapper of Redis.pm that namespaces all Redis calls. It is useful when you have multiple systems using Redis differently in your app.

OPTIONS

METHODS

scan_callback

$ns->scan_callback( sub { my $key = shift; ... } );

$ns->scan_callback( match => 'foo:*', sub { my $key = shift; ... } );

Execute a callback for every matching key within the namespace. The keys are iterated with the Redis SCAN command.

Note that SCAN may return the same key more than once during an iteration, and scan_callback does not deduplicate the results. So the callback may be called more than once for the same key. If your callback has side effects, make it idempotent or deduplicate the keys yourself.

The key is passed as one and only argument to the callback.

AUTHOR

Ichinose Shogo shogo82148@gmail.com

SEE ALSO

LICENSE

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