NAME
Redis::Client::Zset - Work with Redis ordered sets (zsets)
VERSION
version 0.009
SYNOPSIS
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};
DESCRIPTION
This class provides a tie
d 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.
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 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.)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 ) { ... }
CAVEATS
As of Redis 2.4, emptying a zset (with e.g. %zset = ( )
is equivalent to deleting it from the store.
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.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 161:
You forgot a '=back' before '=head1'
- Around line 166:
=back without =over