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
|
|
17
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
88
|
|
12
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
85
|
|
13
|
2
|
|
|
2
|
|
13
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
211
|
|
14
|
2
|
|
|
2
|
|
1534
|
use CBOR::XS qw(encode_cbor decode_cbor); |
|
2
|
|
|
|
|
17781
|
|
|
2
|
|
|
|
|
226
|
|
15
|
2
|
|
|
2
|
|
25
|
use base 'Tie::Hash'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1399
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.004'; # VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub TIEHASH { |
20
|
0
|
|
|
0
|
|
|
my ( $class, $redis, $prefix ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
die "whaa: $redis" unless ref $redis eq 'Redis'; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
$prefix = $prefix ? $prefix . ':' : ''; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $self = { |
27
|
|
|
|
|
|
|
prefix => $prefix, |
28
|
|
|
|
|
|
|
redis => $redis, |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
return bless( $self, $class ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub STORE { |
35
|
0
|
|
|
0
|
|
|
my ( $self, $key, $value ) = @_; |
36
|
0
|
|
|
|
|
|
$self->{redis}->set( $self->{prefix} . $key, encode_cbor($value) ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub FETCH { |
40
|
0
|
|
|
0
|
|
|
my ( $self, $key ) = @_; |
41
|
0
|
|
|
|
|
|
my $data = $self->{redis}->get( $self->{prefix} . $key ); |
42
|
0
|
0
|
|
|
|
|
return unless defined $data; |
43
|
0
|
|
|
|
|
|
decode_cbor($data); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub FIRSTKEY { |
47
|
0
|
|
|
0
|
|
|
my $self = shift; |
48
|
0
|
|
|
|
|
|
$self->{prefix_keys} = [ $self->{redis}->keys( $self->{prefix} . '*' ) ]; |
49
|
0
|
|
|
|
|
|
$self->NEXTKEY; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub NEXTKEY { |
53
|
0
|
|
|
0
|
|
|
my $self = shift; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $key = shift @{ $self->{prefix_keys} }; |
|
0
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
return unless defined $key; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $p = quotemeta $self->{prefix}; |
59
|
0
|
0
|
|
|
|
|
$key =~ s/^$p// if $p; |
60
|
0
|
|
|
|
|
|
return $key; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub EXISTS { |
64
|
0
|
|
|
0
|
|
|
my ( $self, $key ) = @_; |
65
|
0
|
|
|
|
|
|
$self->{redis}->exists( $self->{prefix} . $key ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub DELETE { |
69
|
0
|
|
|
0
|
|
|
my ( $self, $key ) = @_; |
70
|
0
|
|
|
|
|
|
$self->{redis}->del( $self->{prefix} . $key ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub CLEAR { |
74
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
75
|
0
|
|
|
|
|
|
$self->{redis}->del($_) for $self->{redis}->keys( $self->{prefix} . '*' ); |
76
|
0
|
|
|
|
|
|
$self->{prefix_keys} = []; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |