File: README

package info (click to toggle)
libanyevent-memcached-perl 0.08-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 336 kB
  • ctags: 243
  • sloc: perl: 3,494; makefile: 7
file content (246 lines) | stat: -rw-r--r-- 8,035 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
NAME
    AnyEvent::Memcached - AnyEvent memcached client

SYNOPSIS
        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 responce 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];
        }
        } );

DESCRIPTION
    Asyncronous "memcached/memcachedb" client for AnyEvent framework

NOTICE
    There is a notices in Cache::Memcached::AnyEvent related to this module.
    They all has been fixed

    Prerequisites
        We no longer need Object::Event and Devel::Leak::Cb. At all, the
        dependency list is like in Cache::Memcached + AnyEvent

    Binary protocol
        It seems to me, that usage of binary protocol from pure perl gives
        very little advantage. So for now I don't implement it

    Unimplemented Methods
        There is a note, that get_multi is not implementeted. In fact, it
        was implemented by method "get", but the documentation was wrong.

    In general, this module follows the spirit of AnyEvent rather than
    correspondence to Cache::Memcached interface.

METHODS
  new %args
    Currently supported options:

    servers =item namespace =item debug =item cv =item compress_threshold
    =item compress_enable =item timeout =item hasher
        If set, will use instance of this class for hashing instead of
        default. For implementing your own hashing, see sources of
        AnyEvent::Memcached::Hash and AnyEvent::Memcached::Hash::With::Next

    noreply
        If true, additional connection will established for noreply
        commands.

    cas If true, will enable cas/gets commands (since they are not suppotred
        in memcachedb)

  set_servers
        Setup server list

  connect
        Establish connection to all servers and invoke event C<connected>, when ready

  set( $key, $value, [cv => $cv], [ expire => $expire ], cb => $cb->( $rc, $err ) )
    Unconditionally sets a key to a given value in the memcache.

    $rc is

    '1' Successfully stored

    '0' Item was not stored

    undef
        Error happens, see $err

  cas( $key, $cas, $value, [cv => $cv], [ expire => $expire ], cb => $cb->( $rc, $err ) )
        $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"

  add( $key, $value, [cv => $cv], [ expire => $expire ], cb => $cb->( $rc, $err ) )
    Like "set", but only stores in memcache if the key doesn't already
    exist.

  replace( $key, $value, [cv => $cv], [ expire => $expire ], cb => $cb->( $rc, $err ) )
    Like "set", but only stores in memcache if the key already exists. The
    opposite of add.

  append( $key, $value, [cv => $cv], [ expire => $expire ], cb => $cb->( $rc, $err ) )
    Append the $value to the current value on the server under the $key.

    append command first appeared in memcached 1.2.4.

  prepend( $key, $value, [cv => $cv], [ expire => $expire ], cb => $cb->( $rc, $err ) )
    Prepend the $value to the current value on the server under the $key.

    prepend command first appeared in memcached 1.2.4.

  get( $key, [cv => $cv], [ expire => $expire ], cb => $cb->( $rc, $err ) )
    Retrieve the value for a $key. $key should be a scalar

  get( $keys : ARRAYREF, [cv => $cv], [ expire => $expire ], cb => $cb->( $values_hash, $err ) )
    Retrieve the values for a $keys. Return a hash with keys/values

  gets( $key, [cv => $cv], [ expire => $expire ], cb => $cb->( $rc, $err ) )
    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

  gets( $keys : ARRAYREF, [cv => $cv], [ expire => $expire ], cb => $cb->( $rc, $err ) )
    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, [cv => $cv], [ noreply => 1 ], cb => $cb->( $rc, $err ) )
    Delete $key and its value from the cache.

    If "noreply" is true, cb doesn't required

  del
    Alias for "delete"

  remove
    Alias for "delete"

  incr( $key, $increment, [cv => $cv], [ noreply => 1 ], cb => $cb->( $rc, $err ) )
    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.

  decr( $key, $decrement, [cv => $cv], [ noreply => 1 ], cb => $cb->( $rc, $err ) )
    Opposite to "incr"

  rget( $from, $till, [ max => 100 ], [ '+left' => 1 ], [ '+right' => 1 ], [cv => $cv], [ rv => 'array' ], cb => $cb->( $rc, $err ) )
    Memcachedb 1.2.1-beta implements rget method, that allows to look
    through the whole storage

    $from
        the starting key

    $till
        finishing key

    +left
        If true, then starting key will be included in results. true by
        default

    +right
        If true, then finishing key will be included in results. true by
        default

    max Maximum number of results to fetch. 100 is the maximum and is the
        default

    rv  If passed rv => 'array', then the return value will be arrayref with
        values in order, returned by memcachedb.

  incadd ( $key, $increment, [cv => $cv], [ noreply => 1 ], cb => $cb->( $rc, $err ) )
    Increment key, and if it not exists, add it with initial value. If add
    fails, try again to incr or fail

  destroy
    Shutdown object as much, as possible, incl cleaning of incapsulated
    objects

BUGS
    Feature requests are welcome

    Bug reports are welcome

AUTHOR
    Mons Anderson, "<mons at cpan.org>"

COPYRIGHT & LICENSE
    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.