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
|
2
|
|
|
2
|
|
18
|
use strictures 2; |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
109
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Tie::Redis::Candy::Hash; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: tie Perl hashes to Redis hashes - the candy way |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
533
|
use Carp qw(croak); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
109
|
|
14
|
2
|
|
|
2
|
|
1878
|
use CBOR::XS qw(encode_cbor decode_cbor); |
|
2
|
|
|
|
|
9591
|
|
|
2
|
|
|
|
|
147
|
|
15
|
2
|
|
|
2
|
|
13
|
use base 'Tie::Hash'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1037
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.001'; # VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub TIEHASH { |
20
|
2
|
|
|
2
|
|
5
|
my ( $class, $redis, $key ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
2
|
50
|
|
|
|
14
|
croak "not a Redis instance: $redis" |
23
|
|
|
|
|
|
|
unless ref($redis) =~ m{^(?:Test::Mock::)?Redis$}; |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
8
|
my $self = { |
26
|
|
|
|
|
|
|
key => $key, |
27
|
|
|
|
|
|
|
redis => $redis, |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
8
|
return bless( $self, $class ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub STORE { |
34
|
6
|
|
|
6
|
|
1715
|
my ( $self, $key, $value ) = @_; |
35
|
6
|
|
|
|
|
185
|
$self->{redis}->hset( $self->{key}, $key, encode_cbor($value) ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub FETCH { |
39
|
12
|
|
|
12
|
|
5943
|
my ( $self, $key ) = @_; |
40
|
12
|
|
|
|
|
315
|
my $data = $self->{redis}->hget( $self->{key}, $key ); |
41
|
12
|
100
|
|
|
|
2336
|
return unless defined $data; |
42
|
11
|
|
|
|
|
59
|
decode_cbor($data); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub FIRSTKEY { |
46
|
4
|
|
|
4
|
|
2884
|
my $self = shift; |
47
|
4
|
|
|
|
|
113
|
$self->{keys} = [ $self->{redis}->hkeys( $self->{key} ) ]; |
48
|
4
|
|
|
|
|
1368
|
$self->NEXTKEY; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub NEXTKEY { |
52
|
12
|
|
|
12
|
|
18
|
my $self = shift; |
53
|
12
|
|
|
|
|
12
|
shift @{ $self->{keys} }; |
|
12
|
|
|
|
|
72
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub EXISTS { |
57
|
11
|
|
|
11
|
|
4173
|
my ( $self, $key ) = @_; |
58
|
11
|
|
|
|
|
285
|
$self->{redis}->hexists( $self->{key}, $key ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub DELETE { |
62
|
1
|
|
|
1
|
|
643
|
my ( $self, $key ) = @_; |
63
|
1
|
|
|
|
|
31
|
$self->{redis}->hdel( $self->{key}, $key ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub CLEAR { |
67
|
1
|
|
|
1
|
|
2
|
my ($self) = @_; |
68
|
1
|
|
|
|
|
30
|
$self->{redis}->del( $self->{key} ); |
69
|
1
|
|
|
|
|
187
|
delete $self->{keys}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |