| 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 | ▶ | use common::sense 2;m{ | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | use strict; | ||||||||||||
| 24 | use warnings; | ||||||||||||
| 25 | }x; | ||||||||||||
| 26 | 1 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | 1 | ▶ | use base 'AnyEvent::Memcached::Hash'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | |||||||||||||
| 29 | sub peers { | ||||||||||||
| 30 | 41 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
peers: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||
| 31 | 41 | my ($hash,$real,$peers) = @_; | |||||||||||
| 32 | 41 | ▶ | $peers ||= {}; | ||||||||||
|
Condition50%1/2
$peers ||= {}
MC/DC0%0/1
$peers ||= {}
$peers
Truth table50%1/2
A
A= $peers
| |||||||||||||
| 33 | 41 | my $peer = $self->{buckets}->peer( $hash ); | |||||||||||
| 34 | 41 | my $next = $self->{buckets}->next( $peer ); | |||||||||||
| 35 | 41 | ▶ | push @{ $peers->{$peer} ||= [] }, $real; | ||||||||||
|
Condition100%2/2
$peers->{$peer} ||= []
MC/DC100%1/1
$peers->{$peer} ||= []
$peers->{$peer}
Truth table100%2/2
A
A= $peers->{$peer}
| |||||||||||||
| 36 | 41 | ▶ | push @{ $peers->{$next} ||= [] }, $real; | ||||||||||
|
Condition100%2/2
$peers->{$next} ||= []
MC/DC100%1/1
$peers->{$next} ||= []
$peers->{$next}
Truth table100%2/2
A
A= $peers->{$next}
| |||||||||||||
| 37 | 41 | return $peers; | |||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | =head1 AUTHOR | ||||||||||||
| 41 | |||||||||||||
| 42 | Mons Anderson, C<< <mons at cpan.org> >> | ||||||||||||
| 43 | |||||||||||||
| 44 | =cut | ||||||||||||
| 45 | |||||||||||||
| 46 | 1 | 1; | |||||||||||