AnyEvent::Memcached(3pm) | User Contributed Perl Documentation | AnyEvent::Memcached(3pm) |
AnyEvent::Memcached - AnyEvent memcached client
use AnyEvent::Memcached; my $memd = AnyEvent::Memcached->new( servers => [ "10.0.0.15:11211", "10.0.0.15:11212" ], # same as in Cache::Memcached debug => 1, compress_threshold => 10000, namespace => 'my-namespace:', # May use another hashing algo: hasher => 'AnyEvent::Memcached::Hash::WithNext', cv => $cv, # AnyEvent->condvar: group callback ); $memd->set_servers([ "10.0.0.15:11211", "10.0.0.15:11212" ]); # Basic methods are like in Cache::Memcached, but with additional cb => sub { ... }; # first argument to cb is return value, second is the error(s) $memd->set( key => $value, cb => sub { shift or warn "Set failed: @_" } ); # Single get $memd->get( 'key', cb => sub { my ($value,$err) = shift; $err and return warn "Get failed: @_"; warn "Value for key is $value"; } ); # Multi-get $memd->get( [ 'key1', 'key2' ], cb => sub { my ($values,$err) = shift; $err and return warn "Get failed: @_"; warn "Value for key1 is $values->{key1} and value for key2 is $values->{key2}" } ); # Additionally there is rget (see memcachedb-1.2.1-beta) $memd->rget( 'fromkey', 'tokey', cb => sub { my ($values,$err) = shift; $err and warn "Get failed: @_"; while (my ($key,$value) = each %$values) { # ... } } ); # Rget with sorted response values $memd->rget( 'fromkey', 'tokey', rv => 'array' cb => sub { my ($values,$err) = shift; $err and warn "Get failed: @_"; for (0 .. $#values/2) { my ($key,$value) = @$values[$_*2,$_*2+1]; } } );
Asynchronous "memcached/memcachedb" client for AnyEvent framework
There is a notices in Cache::Memcached::AnyEvent related to this module. They all has been fixed
In general, this module follows the spirit of AnyEvent rather than correspondence to Cache::Memcached interface.
Currently supported options:
Setup server list
Establish connection to all servers and invoke event C<connected>, when ready
Unconditionally sets a key to a given value in the memcache.
$rc is
$memd->gets($key, cb => sub { my $value = shift; unless (@_) { # No errors my ($cas,$val) = @$value; # Change your value in $val $memd->cas( $key, $cas, $value, cb => sub { my $rc = shift; if ($rc) { # stored } else { # ... } }); } })
$rc is the same, as for "set"
Store the $value on the server under the $key, but only if CAS value associated with this key is equal to $cas. See also "gets"
Like "set", but only stores in memcache if the key doesn't already exist.
Like "set", but only stores in memcache if the key already exists. The opposite of add.
Append the $value to the current value on the server under the $key.
append command first appeared in memcached 1.2.4.
Prepend the $value to the current value on the server under the $key.
prepend command first appeared in memcached 1.2.4.
Retrieve the value for a $key. $key should be a scalar
Retrieve the values for a $keys. Return a hash with keys/values
Retrieve the value and its CAS for a $key. $key should be a scalar.
$rc is a reference to an array [$cas, $value], or nothing for non-existent key
Retrieve the values and their CAS for a $keys.
$rc is a hash reference with $rc->{$key} is a reference to an array [$cas, $value]
Delete $key and its value from the cache.
If "noreply" is true, cb doesn't required
Alias for "delete"
Alias for "delete"
Increment the value for the $key by $delta. Starting with memcached 1.3.3 $key should be set to a number or the command will fail. Note that the server doesn't check for overflow.
If "noreply" is true, cb doesn't required, and if passed, simply called with rc = 1
Similar to DBI, zero is returned as "0E0", and evaluates to true in a boolean context.
Opposite to "incr"
Memcachedb 1.2.1-beta implements rget method, that allows one to look through the whole storage
Increment key, and if it not exists, add it with initial value. If add fails, try again to incr or fail
Shutdown object as much, as possible, incl cleaning of incapsulated objects
Feature requests are welcome
Bug reports are welcome
Mons Anderson, "<mons at cpan.org>"
Copyright 2009 Mons Anderson, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2022-06-06 | perl v5.34.0 |