PerlOnTheWay has asked for the wisdom of the Perl Monks concerning the following question:

"get" $memd−>get($key); Retrieve the value for a $key. $key should be a scalar. Return: value associated with the $key, or nothing.

If a key doesn't exist, I can nothing.

If it times out, I can nothing either.

How can I distinguish these two different cases after I get nothing from Cache::Memcached::Fast::get ?

Replies are listed 'Best First'.
Re: Can Cache::Memcached::Fast distinguish timeout or not existing?
by Khen1950fx (Canon) on Jun 28, 2012 at 16:39 UTC
    Something similar to this?
    #!/usr/bin/perl use strict; use warnings; use Cache::Memcached::Fast; use Cache::Memcached; use constant count => 2; my %params; foreach my $h (@{$params{servers}}) { $h->{noreply} = 1 if ref($h) eq 'HASH'; } my $another = new Cache::Memcached::Fast(\%params); my @keys = map { "noreply-$_" } (1..count); $another->set_multi(map { [$_, $_] } @keys); my $res = $another->get_multi(@keys); my $count = 0; foreach my $k (@keys) { if ($res->{$k} and $res->{$k} eq $k) { print $res; } else { print "Nothing\n"; } }

      Something similar to this?

      Hmm, lets try that , question: Can ... distinguish timeout or not existing ?

      Answer: Something similar to this?

      Hmm, the question something similar? doesn't answer Can .. yes or no?

      Also, the code doesn't answer the question either

      Too bad

        You didn't answer the question either. Too bad. Post your solution, please.