Changeset 713
- Timestamp:
- 02/23/08 00:47:04 (6 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
r709 r713 336 336 sub _write_and_read { 337 337 my Cache::Memcached $self = shift; 338 my ($sock, $line, $check_complete , $noreply) = @_;338 my ($sock, $line, $check_complete) = @_; 339 339 my $res; 340 340 my ($ret, $offset) = (undef, 0); … … 376 376 } 377 377 if ($res == length($line)) { # all sent 378 $state = $noreply ? 2 :1;378 $state = 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 417 413 $self->{'stats'}->{"delete"}++; 418 414 $key = ref $key ? $key->[1] : $key; 419 415 $time = $time ? " $time" : ""; 420 my $cmd = "delete $self->{namespace}$key$time @params\r\n";421 my $res = _write_and_read($self, $sock, $cmd , undef, $noreply);416 my $cmd = "delete $self->{namespace}$key$time\r\n"; 417 my $res = _write_and_read($self, $sock, $cmd); 422 418 423 419 if ($self->{'stat_callback'}) { … … 451 447 return 0 unless $sock; 452 448 453 my @params;454 my $noreply = not defined wantarray;455 push @params, "noreply" if $noreply;456 457 449 use bytes; # return bytes from length() 458 450 … … 486 478 487 479 local $SIG{'PIPE'} = "IGNORE" unless $FLAG_NOSIGNAL; 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);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); 491 483 492 484 if ($self->{'debug'} && $line) { … … 523 515 $value = 1 unless defined $value; 524 516 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); 517 my $line = "$cmdname $self->{namespace}$key $value\r\n"; 518 my $res = _write_and_read($self, $sock, $line); 531 519 532 520 if ($self->{'stat_callback'}) { … … 789 777 sub flush_all { 790 778 my Cache::Memcached $self = shift; 791 my ($time) = @_;792 793 $time = 0 unless defined $time;794 779 795 780 my $success = 1; 796 781 797 my @params;798 my $noreply = not defined wantarray;799 push @params, "noreply" if $noreply;800 801 782 my @hosts = @{$self->{'buckets'}}; 802 803 # Distribute the delay among the servers. For instance, if $time804 # 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 810 783 foreach my $host (@hosts) { 811 my $delay = int($time);812 $time -= $delay_step;813 my $line = "flush_all $delay @params\r\n";814 784 my $sock = $self->sock_to_host($host); 815 my $res = _write_and_read($self, $sock, $line, undef, $noreply);816 $success = 0 unless ( $noreply or $res eq "OK\r\n");785 my @res = $self->run_command($sock, "flush_all\r\n"); 786 $success = 0 unless (@res); 817 787 } 818 788 … … 821 791 822 792 # returns array of lines, or () on failure. 823 # FIXME: current implementation is broken.824 793 sub run_command { 825 794 my Cache::Memcached $self = shift; … … 829 798 my $line = $cmd; 830 799 while (my $res = _write_and_read($self, $sock, $line)) { 831 # FIXME: _write_and_read() won't handle undefined $line.832 800 undef $line; 833 801 $ret .= $res; 834 # FIXME: end condition is not correct.835 802 last if $ret =~ /(?:OK|END|ERROR)\r\n$/; 836 803 }
