| 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 | use common::sense 2;m{ | ||
| 23 | use strict; | ||
| 24 | use warnings; | ||
| 25 | }x; | ||
| 26 | use Carp; | ||
| 27 | use base 'AnyEvent::Memcached::Hash'; | ||
| 28 | |||
| 29 | sub peers { | ||
| 30 | my $self = shift; | ||
| 31 | my ($hash,$real,$peers) = @_; | ||
| 32 | $peers ||= {}; | ||
| 33 | my $peer = $self->{buckets}->peer( $hash ); | ||
| 34 | my $next = $self->{buckets}->next( $peer ); | ||
| 35 | push @{ $peers->{$peer} ||= [] }, $real; | ||
| 36 | push @{ $peers->{$next} ||= [] }, $real; | ||
| 37 | return $peers; | ||
| 38 | } | ||
| 39 | |||
| 40 | =head1 AUTHOR | ||
| 41 | |||
| 42 | Mons Anderson, C<< <mons at cpan.org> >> | ||
| 43 | |||
| 44 | =cut | ||
| 45 | |||
| 46 | 1; |