« back to index

Solving "CLIENT_ERROR bad command line format. Usage: delete <key> [noreply]" in Memcached

Published on 16th May 2012

After upgrading to Debian 6, I found that deletions in Memcached were not working anymore from PHP. If you run Memcached in verbose mode (memcached -u nobody -vv), you can see what's happening:

<30 delete nameofthekey 1
>30 CLIENT_ERROR bad command line format.  Usage: delete <key> [noreply]

This is because of a change in the Memcached protocol, which doesn't seem to allow a timeout anymore, and some versions of Memcached extension seem to set it to 1 by default, as you can see in the logs. I was using packages memcached 1.4.5 and php5-memcache 3.0.4.

So find all your occurrences of memcache_delete() or $foo->delete() where $foo is an instance of the Memcache object, and add a 0 at the end, like this:

memcache_delete($mc, 'nameofthekey', 0);

or

$mc->delete('nameofthekey', 0);

If you see the Memcached logs you will see it will work again:

<30 delete nameofthekey
>30 DELETED