File: WithNext.pm

package info (click to toggle)
libanyevent-memcached-perl 0.08-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 332 kB
  • sloc: perl: 3,494; makefile: 7
file content (46 lines) | stat: -rw-r--r-- 1,029 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package AnyEvent::Memcached::Hash::WithNext;

=head1 NAME

AnyEvent::Memcached::Hash::WithNext - Hashing algorythm for AE::Memcached

=head1 SYNOPSIS

    my $memd = AnyEvent::Memcached->new(
        servers => [ "10.0.0.15:10001", "10.0.0.15:10002", "10.0.0.15:10003" ],
        # ...
        hasher  => 'AnyEvent::Memcached::Hash::WithNext',
    );
    $memd->set(key => "val", ...) # will put key on 2 servers

=head1 DESCRIPTION

Uses the same hashing, as default, but always put key to server, next after chosen. Result is twice-replicated data. Useful for usage with memcachdb

=cut

use common::sense 2;m{
use strict;
use warnings;
}x;
use Carp;
use base 'AnyEvent::Memcached::Hash';

sub peers {
	my $self = shift;
	my ($hash,$real,$peers) = @_;
	$peers ||= {};
	my $peer = $self->{buckets}->peer( $hash );
	my $next = $self->{buckets}->next( $peer );
	push @{ $peers->{$peer} ||= [] }, $real;
	push @{ $peers->{$next} ||= [] }, $real;
	return $peers;
}

=head1 AUTHOR

Mons Anderson, C<< <mons at cpan.org> >>

=cut

1;