Changeset 709
- Timestamp:
- 02/22/08 04:57:47 (9 months ago)
- Files:
-
- trunk/api/perl/lib/Cache/Memcached.pm (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/api/perl/lib/Cache/Memcached.pm
r634 r709 336 336 sub _write_and_read { 337 337 my Cache::Memcached $self = shift; 338 my ($sock, $line, $check_complete ) = @_;338 my ($sock, $line, $check_complete, $noreply) = @_; 339 339 my $res; 340 340 my ($ret, $offset) = (undef, 0); … … 376 376 } 377 377 if ($res == length($line)) { # all sent 378 $state = 1;378 $state = $noreply ? 2 : 1; 379 379 } else { # we only succeeded in sending some of it 380 380 substr($line, 0, $res, ''); # delete the part we sent … … 411 411 return 0 unless $sock; 412 412 413 my @params; 414 my $noreply = not defined wantarray; 415 push @params, "noreply" if $noreply; 416 413 417 $self->{'stats'}->{"delete"}++; 414 418 $key = ref $key ? $key->[1] : $key; 415 419 $time = $time ? " $time" : ""; 416 my $cmd = "delete $self->{namespace}$key$time \r\n";417 my $res = _write_and_read($self, $sock, $cmd );420 my $cmd = "delete $self->{namespace}$key$time @params\r\n"; 421 my $res = _write_and_read($self, $sock, $cmd, undef, $noreply); 418 422 419 423 if ($self->{'stat_callback'}) { … … 447 451 return 0 unless $sock; 448 452 453 my @params; 454 my $noreply = not defined wantarray; 455 push @params, "noreply" if $noreply; 456 449 457 use bytes; # return bytes from length() 450 458 … … 478 486 479 487 local $SIG{'PIPE'} = "IGNORE" unless $FLAG_NOSIGNAL; 480 my $line = "$cmdname $self->{namespace}$key $flags $exptime $len \r\n$val\r\n";481 482 my $res = _write_and_read($self, $sock, $line );488 my $line = "$cmdname $self->{namespace}$key $flags $exptime $len @params\r\n$val\r\n"; 489 490 my $res = _write_and_read($self, $sock, $line, undef, $noreply); 483 491 484 492 if ($self->{'debug'} && $line) { … … 515 523 $value = 1 unless defined $value; 516 524 517 my $line = "$cmdname $self->{namespace}$key $value\r\n"; 518 my $res = _write_and_read($self, $sock, $line); 525 my @params; 526 my $noreply = not defined wantarray; 527 push @params, "noreply" if $noreply; 528 529 my $line = "$cmdname $self->{namespace}$key $value @params\r\n"; 530 my $res = _write_and_read($self, $sock, $line, undef, $noreply); 519 531 520 532 if ($self->{'stat_callback'}) { … … 777 789 sub flush_all { 778 790 my Cache::Memcached $self = shift; 791 my ($time) = @_; 792 793 $time = 0 unless defined $time; 779 794 780 795 my $success = 1; 781 796 797 my @params; 798 my $noreply = not defined wantarray; 799 push @params, "noreply" if $noreply; 800 782 801 my @hosts = @{$self->{'buckets'}}; 802 803 # Distribute the delay among the servers. For instance, if $time 804 # is 30 seconds, and we have 3 servers, they will get 30, 15, 0. 805 my $delay_step = 0; 806 if (@hosts > 1) { 807 $delay_step = $time / (@hosts - 1); 808 } 809 783 810 foreach my $host (@hosts) { 811 my $delay = int($time); 812 $time -= $delay_step; 813 my $line = "flush_all $delay @params\r\n"; 784 814 my $sock = $self->sock_to_host($host); 785 my @res = $self->run_command($sock, "flush_all\r\n");786 $success = 0 unless ( @res);815 my $res = _write_and_read($self, $sock, $line, undef, $noreply); 816 $success = 0 unless ($noreply or $res eq "OK\r\n"); 787 817 } 788 818 … … 791 821 792 822 # returns array of lines, or () on failure. 823 # FIXME: current implementation is broken. 793 824 sub run_command { 794 825 my Cache::Memcached $self = shift; … … 798 829 my $line = $cmd; 799 830 while (my $res = _write_and_read($self, $sock, $line)) { 831 # FIXME: _write_and_read() won't handle undefined $line. 800 832 undef $line; 801 833 $ret .= $res; 834 # FIXME: end condition is not correct. 802 835 last if $ret =~ /(?:OK|END|ERROR)\r\n$/; 803 836 }
