| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Model::Envoy::Storage::Redis; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.1.3'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
760258
|
use Moose; |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
8
|
|
|
6
|
1
|
|
|
1
|
|
7384
|
use MooseX::ClassAttribute; |
|
|
1
|
|
|
|
|
79551
|
|
|
|
1
|
|
|
|
|
4
|
|
|
7
|
1
|
|
|
1
|
|
311518
|
use JSON::XS; |
|
|
1
|
|
|
|
|
4932
|
|
|
|
1
|
|
|
|
|
363
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'Model::Envoy::Storage'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 Model::Envoy::Storage::Redis |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
A storage plugin for C<Model::Envoy> that conforms to C<Model::Envoy::Storage>. |
|
14
|
|
|
|
|
|
|
It does not implement C<list> at the moment, but will fetch, store and delete |
|
15
|
|
|
|
|
|
|
objects out of the key-value store. |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
class_has 'redis' => ( |
|
20
|
|
|
|
|
|
|
is => 'rw', |
|
21
|
|
|
|
|
|
|
isa => 'Redis::Fast', |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub configure { |
|
25
|
1
|
|
|
1
|
1
|
38950
|
my ( $plugin_class, $envoy_class, $conf ) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$plugin_class->redis( |
|
28
|
|
|
|
|
|
|
ref $conf->{redis} eq 'CODE' ? $conf->{redis}->($envoy_class) : $conf->{redis} |
|
29
|
1
|
50
|
|
|
|
10
|
); |
|
30
|
1
|
|
|
|
|
5
|
$conf->{_configured} = 1; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub fetch { |
|
34
|
3
|
|
|
3
|
1
|
9699
|
my $self = shift; |
|
35
|
3
|
|
|
|
|
6
|
my $model_class = shift; |
|
36
|
|
|
|
|
|
|
|
|
37
|
3
|
|
|
|
|
6
|
my $id = do { |
|
38
|
|
|
|
|
|
|
|
|
39
|
3
|
100
|
|
|
|
9
|
if ( @_ == 1 ) { |
|
40
|
2
|
|
|
|
|
4
|
$_[0]; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
else { |
|
43
|
1
|
|
|
|
|
4
|
my %params = @_; |
|
44
|
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
4
|
$params{id}; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
}; |
|
48
|
|
|
|
|
|
|
|
|
49
|
3
|
100
|
|
|
|
124
|
if ( my $result = $self->redis->get( 'id:' . $id ) ) { |
|
50
|
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
25
|
return $model_class->build( decode_json( $result ) ); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
12
|
return undef; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub save { |
|
58
|
1
|
|
|
1
|
1
|
158
|
my ( $self ) = @_; |
|
59
|
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
32
|
$self->redis->set( 'id:' . $self->model->id => encode_json( $self->model->dump ) ); |
|
61
|
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
693
|
return $self; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub list { |
|
66
|
|
|
|
|
|
|
|
|
67
|
1
|
|
|
1
|
1
|
3476
|
return undef; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub delete { |
|
71
|
1
|
|
|
1
|
1
|
5828
|
my ( $self ) = @_; |
|
72
|
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
32
|
$self->redis->del( 'id:' . $self->model->id ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
40
|
return; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub in_storage { |
|
79
|
3
|
|
|
3
|
0
|
2042
|
my ( $self ) = @_; |
|
80
|
|
|
|
|
|
|
|
|
81
|
3
|
100
|
|
|
|
92
|
return $self->redis->exists( 'id:' . $self->model->id ) ? 1 : 0; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |