Redis::Client::Zset - Work with Redis ordered sets (zsets)
version 0.011
use Redis::Client; my $client = Redis::Client->new; tie my %set, 'Redis::Client::Zset', key => 'my_zset', client => $client; my @members = keys %zset; $zset{foo} = 0.6; print 1 if exists $zset{bar};
This class provides a tied interface for Redis sorted sets (zsets). Redis zsets are mapped to Perl hashes. Like Perl hashes, Redis zsets contain an unordered group of "members" which are mapped to keys in the hash. The values in a hash tied to a Redis zset are numeric scores which control the sort order. Adding a value to a Redis set will cause the member to be created if it does not already exist. The value determines the new member's ordering with respect to the other members.
tie
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 zsets.
delete
Removes a member from the zset. (Note that this is not the same as setting the value to undef, in which case the member still exists.)
undef
delete $zset{foo};
exists
Check if a member exists in the zset.
print 1 if exists $zset{blargh};
keys
Retrieves a list of all members in the zset, in sorted order.
my @members = keys %zset;
values
Retrieves a list of all "values" in the zset. These are the numeric scores associated with each member. The list is returned sorted.
my @scores = values %zset;
each
Iterate over key/value pairs from the hash. The keys are the members and the values are the scores. The keys and values are returned in sorted order.
while( my ( $key, $val ) = each %zset ) { ... }
As of Redis 2.4, emptying a zset (with e.g. %zset = ( ) is equivalent to deleting it from the store.
%zset = ( )
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.
2 POD Errors
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
=back without =over
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.