NAME
Redis::Client::Set - Work with Redis sets
VERSION
version 0.009
SYNOPSIS
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};
DESCRIPTION
This class provides a tie
d 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.
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.
INTERFACE
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
undef
s. 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 ) { ... }
SEE ALSO
EXTENDS
CONSUMES
AUTHOR
Mike Friedman <friedo@friedo.com>
COPYRIGHT AND LICENSE
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.