The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Redis::Client::List - Work with Redis lists

VERSION

version 0.015

SYNOPSIS

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

DESCRIPTION

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.

INTERFACE

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.

delete $list[3];    # sets to undef
push

Adds elements to the end of the list, using the Redis RPUSH command.

push @list, 'foo', 'bar', 'baz';
pop

Removes the last element of the list and returns it, using the Redis RPOP command.

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.

my $first = shift @list;
unshift

Adds elements to the beginning of a list, using the Redis LPUSH command.

unshift @list, 'quux', 'narf';

CAVEATS

The splice operator is not yet supported for Redis lists.

SEE ALSO

Redis::Client

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.