line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::Memcached::Hash::WithNext; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
AnyEvent::Memcached::Hash::WithNext - Hashing algorythm for AE::Memcached |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $memd = AnyEvent::Memcached->new( |
10
|
|
|
|
|
|
|
servers => [ "10.0.0.15:10001", "10.0.0.15:10002", "10.0.0.15:10003" ], |
11
|
|
|
|
|
|
|
# ... |
12
|
|
|
|
|
|
|
hasher => 'AnyEvent::Memcached::Hash::WithNext', |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
$memd->set(key => "val", ...) # will put key on 2 servers |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Uses the same hashing, as default, but always put key to server, next after choosen. Result is twice-replicated data. Useful for usage with memcachdb |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
458
|
use common::sense 2;m{ |
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
5
|
|
23
|
|
|
|
|
|
|
use strict; |
24
|
|
|
|
|
|
|
use warnings; |
25
|
|
|
|
|
|
|
}x; |
26
|
1
|
|
|
1
|
|
57
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
27
|
1
|
|
|
1
|
|
5
|
use base 'AnyEvent::Memcached::Hash'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
234
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub peers { |
30
|
41
|
|
|
41
|
0
|
46
|
my $self = shift; |
31
|
41
|
|
|
|
|
53
|
my ($hash,$real,$peers) = @_; |
32
|
41
|
|
50
|
|
|
78
|
$peers ||= {}; |
33
|
41
|
|
|
|
|
125
|
my $peer = $self->{buckets}->peer( $hash ); |
34
|
41
|
|
|
|
|
119
|
my $next = $self->{buckets}->next( $peer ); |
35
|
41
|
|
100
|
|
|
56
|
push @{ $peers->{$peer} ||= [] }, $real; |
|
41
|
|
|
|
|
203
|
|
36
|
41
|
|
100
|
|
|
47
|
push @{ $peers->{$next} ||= [] }, $real; |
|
41
|
|
|
|
|
167
|
|
37
|
41
|
|
|
|
|
142
|
return $peers; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 AUTHOR |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Mons Anderson, C<< >> |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |