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::Hash; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: tie Perl hashes to Redis hashes - the candy way |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
48
|
|
12
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
49
|
|
13
|
2
|
|
|
2
|
|
9
|
use Carp qw(croak); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
121
|
|
14
|
2
|
|
|
2
|
|
1872
|
use CBOR::XS qw(encode_cbor decode_cbor); |
|
2
|
|
|
|
|
14991
|
|
|
2
|
|
|
|
|
150
|
|
15
|
2
|
|
|
2
|
|
15
|
use base 'Tie::Hash'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
990
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.000'; # VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub TIEHASH { |
20
|
2
|
|
|
2
|
|
6
|
my ( $class, $redis, $key ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
2
|
50
|
|
|
|
20
|
croak "not a Redis instance: $redis" |
23
|
|
|
|
|
|
|
unless ref($redis) =~ m{^(?:Test::Mock::)?Redis$}; |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
9
|
my $self = { |
26
|
|
|
|
|
|
|
key => $key, |
27
|
|
|
|
|
|
|
redis => $redis, |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
11
|
return bless( $self, $class ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub STORE { |
34
|
6
|
|
|
6
|
|
1944
|
my ( $self, $key, $value ) = @_; |
35
|
6
|
|
|
|
|
243
|
$self->{redis}->hset( $self->{key}, $key, encode_cbor($value) ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub FETCH { |
39
|
12
|
|
|
12
|
|
6369
|
my ( $self, $key ) = @_; |
40
|
12
|
|
|
|
|
383
|
my $data = $self->{redis}->hget( $self->{key}, $key ); |
41
|
12
|
100
|
|
|
|
2852
|
return unless defined $data; |
42
|
11
|
|
|
|
|
72
|
decode_cbor($data); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub FIRSTKEY { |
46
|
4
|
|
|
4
|
|
3532
|
my $self = shift; |
47
|
4
|
|
|
|
|
129
|
$self->{keys} = [ $self->{redis}->hkeys( $self->{key} ) ]; |
48
|
4
|
|
|
|
|
1642
|
$self->NEXTKEY; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub NEXTKEY { |
52
|
12
|
|
|
12
|
|
21
|
my $self = shift; |
53
|
12
|
|
|
|
|
16
|
shift @{ $self->{keys} }; |
|
12
|
|
|
|
|
63
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub EXISTS { |
57
|
11
|
|
|
11
|
|
4364
|
my ( $self, $key ) = @_; |
58
|
11
|
|
|
|
|
386
|
$self->{redis}->hexists( $self->{key}, $key ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub DELETE { |
62
|
1
|
|
|
1
|
|
691
|
my ( $self, $key ) = @_; |
63
|
1
|
|
|
|
|
58
|
$self->{redis}->hdel( $self->{key}, $key ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub CLEAR { |
67
|
1
|
|
|
1
|
|
3
|
my ($self) = @_; |
68
|
1
|
|
|
|
|
29
|
$self->{redis}->del( $self->{key} ); |
69
|
1
|
|
|
|
|
175
|
delete $self->{keys}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |