Redis::Client::Set - Work with Redis sets
version 0.015
use Redis::Client; my $client = Redis::Client->new; tie my %set, 'Redis::Client::Set', key => 'my_set', client => $client; my @members = keys %set; $set{foo} = undef; print 1 if exists $set{bar};
This class provides a tied interface for Redis sets. Redis sets are mapped to Perl hashes. Like Perl hashes, Redis sets contain an unordered group of "members" which are mapped to keys in the hash. The values in a hash tied to a Redis set are ALWAYS undef. Adding a value to a Redis set will cause the member to be created if it does not already exist, but the value will be discarded.
tie
undef
Any time the hash is evaluated or the existence of a key is tested, the corresponding value will be fetched from the Redis store. Any time a key is added or deleted, the change will be written to the Redis store.
The following Perl builtins will work the way you expect on Redis sets.
delete
Removes a member from the set. (Note that this is not the same as setting the value to undef, in which case the member still exists.)
delete $set{foo};
exists
Check if a member exists in the set.
print 1 if exists $set{blargh};
keys
Retrieves a list of all members in the set, in no particular order.
my @members = keys %set;
values
Retrieves a list of all "values" in the set. This will always be a list of undefs. Not very useful.
my @vals = values %set;
each
Iterate over key/value pairs from the hash. The values will always be undef.
while( my ( $key, $val ) = each %set ) { ... }
Moose::Object
Redis::Client::Role::Tied
Mike Friedman <friedo@friedo.com>
This software is copyright (c) 2011 by Mike Friedman.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Redis::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Redis::Client
CPAN shell
perl -MCPAN -e shell install Redis::Client
For more information on module installation, please visit the detailed CPAN module installation guide.