line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# This file was part of Redis, licensed under: |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# The Artistic License 2.0 (GPL Compatible) |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Copyright (c) 2015 by Pedro Melo, Damien Krotkine. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Tie::Redis::Candy::Array; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: tie Perl arrays to Redis lists - the candy way |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
19
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
88
|
|
12
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
63
|
|
13
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
122
|
|
14
|
2
|
|
|
2
|
|
11
|
use CBOR::XS qw(encode_cbor decode_cbor); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
103
|
|
15
|
2
|
|
|
2
|
|
19
|
use base 'Tie::Array'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1088
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.004'; # VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub TIEARRAY { |
20
|
0
|
|
|
0
|
|
|
my ( $class, $redis, $listname ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $self = { |
23
|
|
|
|
|
|
|
list => $listname, |
24
|
|
|
|
|
|
|
redis => $redis, |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return bless( $self, $class ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub FETCH { |
31
|
0
|
|
|
0
|
|
|
my ( $self, $index ) = @_; |
32
|
0
|
|
|
|
|
|
my $data = $self->{redis}->lindex( $self->{list}, $index ); |
33
|
0
|
0
|
|
|
|
|
return unless defined $data; |
34
|
0
|
|
|
|
|
|
decode_cbor($data); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub FETCHSIZE { |
38
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
39
|
0
|
|
|
|
|
|
$self->{redis}->llen( $self->{list} ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub STORE { |
43
|
0
|
|
|
0
|
|
|
my ( $self, $index, $value ) = @_; |
44
|
0
|
|
|
|
|
|
$self->{redis}->lset( $self->{list}, $index, encode_cbor($value) ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub STORESIZE { |
48
|
0
|
|
|
0
|
|
|
my ( $self, $count ) = @_; |
49
|
0
|
|
|
|
|
|
$self->{redis}->ltrim( $self->{list}, 0, $count ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub CLEAR { |
53
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
54
|
0
|
|
|
|
|
|
$self->{redis}->del( $self->{list} ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub PUSH { |
58
|
0
|
|
|
0
|
|
|
my ( $self, @values ) = @_; |
59
|
0
|
|
|
|
|
|
$self->{redis}->rpush( $self->{list}, encode_cbor($_) ) for @values; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub POP { |
63
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
64
|
0
|
0
|
|
|
|
|
map { defined($_) ? decode_cbor($_) : undef } |
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$self->{redis}->rpop( $self->{list} ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub SHIFT { |
69
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
70
|
0
|
0
|
|
|
|
|
map { defined($_) ? decode_cbor($_) : undef } |
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$self->{redis}->lpop( $self->{list} ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub UNSHIFT { |
75
|
0
|
|
|
0
|
|
|
my ( $self, @values ) = shift; |
76
|
0
|
|
|
|
|
|
$self->{redis}->lpush( $self->{list}, encode_cbor($_) ) for @values; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub SPLICE { |
80
|
0
|
|
|
0
|
|
|
my ( $self, $offset, $length ) = @_; |
81
|
0
|
0
|
|
|
|
|
confess "cannot replace elements in list (unimplemented)" if @_ > 3; |
82
|
0
|
|
|
|
|
|
$self->lrange( $self->{list}, $offset, $length ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub EXTEND { |
86
|
0
|
|
|
0
|
|
|
my ( $self, $count ) = @_; |
87
|
|
|
|
|
|
|
$self->{redis}->rpush( $self->{list}, '' ) |
88
|
0
|
|
|
|
|
|
for ( $self->FETCHSIZE .. ( $count - 1 ) ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
0
|
|
|
sub DESTROY { |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |