Redis::Client::List - Work with Redis lists
version 0.013
use Redis::Client; my $client = Redis::Client->new; tie my @list, 'Redis::Client::List', key => 'my_list', client => $client; @list = ( 1, 2, 3 ); push @list, 4, 5, 6; my $val = $list[0]; # 1 my $val2 = pop @list; # 6
This class provides a tied interface to Redis lists. Redis lists are mapped to Perl arrays. Like Perl arrays, a Redis list contains an ordered sequence of values. Any time the list or an element from the list is evaluated, its current value will be fetched from the Redis store. Any time the tied array or an element of the tied array is changed, its new value will be written to the Redis store.
tie
The following Perl builtins will work the way you expect on Redis lists.
exists
Returns a true value if the size of the Redis list has an index this high.
print 'List has at least 43 elements' if exists $list[42];
delete
Deletes the item stored at an index, setting its value to undef. It does NOT shift the rest of the list down.
undef
delete $list[3]; # sets to undef
push
Adds elements to the end of the list, using the Redis RPUSH command.
RPUSH
push @list, 'foo', 'bar', 'baz';
pop
Removes the last element of the list and returns it, using the Redis RPOP command.
RPOP
my $last = pop @list;
shift
Removes an element from the beginning of the list and shifts the remaining elements down, using the Redis LPOP command.
LPOP
my $first = shift @list;
unshift
Adds elements to the beginning of a list, using the Redis LPUSH command.
LPUSH
unshift @list, 'quux', 'narf';
The splice operator is not yet supported for Redis lists.
splice
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.