line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::Driver::Redis; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
695
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
4
|
1
|
|
|
1
|
|
1458
|
use Redis; |
|
1
|
|
|
|
|
143298
|
|
|
1
|
|
|
|
|
62
|
|
5
|
1
|
|
|
1
|
|
428113
|
use URI::Escape qw(uri_escape uri_unescape); |
|
1
|
|
|
|
|
2681
|
|
|
1
|
|
|
|
|
1361
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends 'CHI::Driver'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'redis' => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
lazy => 1, |
14
|
|
|
|
|
|
|
builder => '_build_redis', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'redis_options' => ( |
18
|
|
|
|
|
|
|
is => 'rw', |
19
|
|
|
|
|
|
|
default => sub { {} }, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'redis_class' => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
default => 'Redis', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'prefix'=> ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
default => '', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub BUILD { |
33
|
152
|
|
|
152
|
0
|
28756
|
my ($self, $params) = @_; |
34
|
152
|
|
|
|
|
306
|
foreach my $param (qw/redis redis_class redis_options prefix/) { |
35
|
608
|
100
|
|
|
|
1586
|
if (exists $params->{$param}) { |
36
|
306
|
|
|
|
|
664
|
delete $params->{$param}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
my %options = ( |
40
|
|
|
|
|
|
|
server => '127.0.0.1:6379', |
41
|
|
|
|
|
|
|
encoding => undef, |
42
|
152
|
|
|
|
|
515
|
%{ $self->redis_options() }, |
43
|
152
|
|
|
|
|
233
|
%{ $self->non_common_constructor_params($params) }, |
|
152
|
|
|
|
|
515
|
|
44
|
|
|
|
|
|
|
); |
45
|
152
|
|
|
|
|
6405
|
$self->redis_options(\%options); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _build_redis { |
49
|
146
|
|
|
146
|
|
1576
|
my ($self) = @_; |
50
|
146
|
|
|
|
|
343
|
return $self->redis_class()->new(%{ $self->redis_options() }); |
|
146
|
|
|
|
|
936
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub fetch { |
54
|
1727
|
|
|
1727
|
0
|
6681778
|
my ($self, $key) = @_; |
55
|
|
|
|
|
|
|
|
56
|
1727
|
|
|
|
|
4285
|
my $eskey = uri_escape($key); |
57
|
1727
|
|
|
|
|
26579
|
my $realkey = $self->prefix . $self->namespace . '||' . $eskey; |
58
|
1727
|
|
|
|
|
38420
|
my $val = $self->redis->get($realkey); |
59
|
1727
|
|
|
|
|
175336
|
return $val; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub fetch_multi_hashref { |
63
|
11
|
|
|
11
|
0
|
17622
|
my ($self, $keys) = @_; |
64
|
|
|
|
|
|
|
|
65
|
11
|
100
|
|
|
|
21
|
return unless scalar(@{ $keys }); |
|
11
|
|
|
|
|
47
|
|
66
|
|
|
|
|
|
|
|
67
|
9
|
|
|
|
|
39
|
my $ns = $self->prefix . $self->namespace; |
68
|
|
|
|
|
|
|
|
69
|
9
|
|
|
|
|
21
|
my @keys; |
70
|
9
|
|
|
|
|
20
|
foreach my $k (@$keys) { |
71
|
61
|
|
|
|
|
175
|
my $esk = uri_escape($k); |
72
|
61
|
|
|
|
|
2557
|
my $key = $ns . '||' . $esk; |
73
|
61
|
|
|
|
|
130
|
push @keys, $key; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
9
|
|
|
|
|
237
|
my @vals = $self->redis->mget(@keys); |
77
|
|
|
|
|
|
|
|
78
|
9
|
|
|
|
|
2124
|
my $count = 0; |
79
|
9
|
|
|
|
|
24
|
my %resp; |
80
|
9
|
|
|
|
|
30
|
foreach my $k (@$keys) { |
81
|
61
|
|
|
|
|
165
|
$resp{$k} = $vals[$count]; |
82
|
61
|
|
|
|
|
104
|
$count++; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
9
|
|
|
|
|
49
|
return \%resp; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub get_keys { |
89
|
124
|
|
|
124
|
0
|
57734
|
my ($self) = @_; |
90
|
|
|
|
|
|
|
|
91
|
124
|
|
|
|
|
2881
|
my @keys = $self->redis->smembers($self->prefix . $self->namespace); |
92
|
|
|
|
|
|
|
|
93
|
124
|
|
|
|
|
13531
|
my @unesckeys = (); |
94
|
|
|
|
|
|
|
|
95
|
124
|
|
|
|
|
246
|
foreach my $k (@keys) { |
96
|
|
|
|
|
|
|
# Getting an empty key here for some reason... |
97
|
615
|
50
|
|
|
|
10531
|
next unless defined $k; |
98
|
615
|
|
|
|
|
1354
|
push(@unesckeys, uri_unescape($k)); |
99
|
|
|
|
|
|
|
} |
100
|
124
|
|
|
|
|
3188
|
return @unesckeys; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub get_namespaces { |
104
|
11
|
|
|
11
|
0
|
10623
|
my ($self) = @_; |
105
|
|
|
|
|
|
|
|
106
|
11
|
|
|
|
|
308
|
return $self->redis->smembers($self->prefix . 'chinamespaces'); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub remove { |
110
|
131
|
|
|
131
|
0
|
143713
|
my ($self, $key) = @_; |
111
|
|
|
|
|
|
|
|
112
|
131
|
50
|
|
|
|
333
|
return unless defined($key); |
113
|
|
|
|
|
|
|
|
114
|
131
|
|
|
|
|
391
|
my $ns = $self->prefix . $self->namespace; |
115
|
|
|
|
|
|
|
|
116
|
131
|
|
|
|
|
357
|
my $skey = uri_escape($key); |
117
|
|
|
|
|
|
|
|
118
|
131
|
|
|
|
|
4887
|
$self->redis->srem($ns, $skey); |
119
|
131
|
|
|
|
|
19717
|
$self->redis->del($ns . '||' . $skey); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub store { |
123
|
547
|
|
|
547
|
0
|
363343
|
my ($self, $key, $data, $expires_in) = @_; |
124
|
|
|
|
|
|
|
|
125
|
547
|
|
|
|
|
1580
|
my $ns = $self->prefix . $self->namespace; |
126
|
|
|
|
|
|
|
|
127
|
547
|
|
|
|
|
1385
|
my $skey = uri_escape($key); |
128
|
547
|
|
|
|
|
11803
|
my $realkey = $ns . '||' . $skey; |
129
|
|
|
|
|
|
|
|
130
|
547
|
|
|
|
|
12063
|
$self->redis->sadd($self->prefix . 'chinamespaces', $self->namespace); |
131
|
547
|
|
|
|
|
145100
|
$self->redis->sadd($ns, $skey); |
132
|
547
|
|
|
|
|
140019
|
$self->redis->set($realkey, $data); |
133
|
|
|
|
|
|
|
|
134
|
547
|
100
|
|
|
|
55360
|
if (defined($expires_in)) { |
135
|
2
|
|
|
|
|
42
|
$self->redis->expire($realkey, $expires_in); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub clear { |
140
|
114
|
|
|
114
|
0
|
59611
|
my ($self) = @_; |
141
|
|
|
|
|
|
|
|
142
|
114
|
|
|
|
|
456
|
my $ns = $self->prefix . $self->namespace; |
143
|
114
|
|
|
|
|
2644
|
my @keys = $self->redis->smembers($ns); |
144
|
|
|
|
|
|
|
|
145
|
114
|
|
|
|
|
14667
|
foreach my $k (@keys) { |
146
|
88
|
|
|
|
|
10883
|
$self->redis->srem($ns, $k); |
147
|
88
|
|
|
|
|
12963
|
$self->redis->del($ns . '||' . $k); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
__END__ |