Alexandre Kalendarev
Alexandre Kalendarev

Reputation: 681

Do You know, how to use ADD command into memcached?

I'm using in my project many counters by memcached:

$data = $mc->set('sasa', 100);
$data = $mc->get('sasa');
var_dump($data);
$res =  $mc->add('sasa', 100);
var_dump($res);

result is

int(100)
bool(false)
int(100)

If I use memcached native protocol:

get sasa
VALUE sasa 1 3
100
END
add sasa 0 0 1
1
NOT_STORE
get sasa 
VALUE sasa 1 3
100
END

ADD command is not work. https://github.com/memcached/memcached/blob/master/doc/protocol.txt#L132

Do You know, how to use ADD command in the memcached?

Upvotes: 0

Views: 415

Answers (3)

mikewied
mikewied

Reputation: 5333

The behavior you showed in your example is what should be expected. The ADD command will only add a key if it does not already exist.

Upvotes: 1

Lajos Veres
Lajos Veres

Reputation: 13725

I think you would like to increment a counter. You can do this with the incr protocoll level or the Memcache::increment commands.

http://php.net/manual/en/memcache.increment.php

Upvotes: 0

srain
srain

Reputation: 9082

It may be that the usage of memory has reach the limit. Check it please, if yes, change the limit value in your config file.

Upvotes: 0

Related Questions