Memcached
Use a Memcached cache: get, put, add, replace, append, compare-and-set, counters and expiry. Typical uses: share a cache with other applications, count events.
memcached pingmemcached putmemcached putmemcached getmemcached get_manymemcached addmemcached addmemcached replacememcached replacememcached appendmemcached prependmemcached getsmemcached casmemcached casmemcached incrmemcached incrmemcached decrmemcached decrmemcached touchmemcached deletememcached infomemcached infomemcached flush

memcached ping <config>


Description

    A quick test of the connection: {version}

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
admin
memcached ping "{\"host\": \"127.0.0.1\"}"
mentdb
{"version": "1.6.39"}

memcached put <config> <key> <value>


Description

    Store a value (the set command: created or replaced). Returns {key, stored}

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    value:   The value (a text in UTF-8, 64 MB at most; the server limit is often 1 MB) - String - required
admin
memcached put "{\"host\": \"127.0.0.1\"}" "greeting" "héllo"
mentdb
{"key": "greeting", "stored": true}

memcached put <config> <key> <value> <json_params>


Description

    Store a value with parameters

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    value:   The value (a text in UTF-8, 64 MB at most; the server limit is often 1 MB) - String - required
    json_params:   The parameters: ttl (seconds, 0 = no expiry, 2592000 = 30 days at most), flags (an integer of 32 bits kept with the value) - String - required
admin
memcached put "{\"host\": \"127.0.0.1\"}" "session:42" "{\"user\": \"zoe\"}" "{\"ttl\": 600, \"flags\": 1}"
mentdb
{"key": "session:42", "stored": true}

memcached get <config> <key>


Description

    Read a value; null if the key does not exist (or expired)

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
admin
memcached get "{\"host\": \"127.0.0.1\"}" "greeting"
mentdb
héllo
no such key, with a short time-out (fixed result: real memcached 1.6.39)
admin
memcached get "{\"host\": \"127.0.0.1\", \"port\": 11211, \"timeout_ms\": 3000}" "nothing"
mentdb
null

memcached get_many <config> <json_keys_or_key>


Description

    Read several keys in one command: a JSON object {key: value} of the keys found, in the order asked

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    json_keys_or_key:   A JSON array of keys, or one key - String - required
admin
memcached get_many "{\"host\": \"127.0.0.1\"}" "[\"greeting\", \"nothing\", \"session:42\"]"
mentdb
{"greeting": "héllo", "session:42": "{\"user\": \"zoe\"}"}

memcached add <config> <key> <value>


Description

    Store only if the key does not exist. Returns 1, or 0 if it exists

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    value:   The value (a text in UTF-8, 64 MB at most; the server limit is often 1 MB) - String - required
admin
memcached add "{\"host\": \"127.0.0.1\"}" "greeting" "other"
mentdb
0

memcached add <config> <key> <value> <json_params>


Description

    Add with parameters: a lock that expires

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    value:   The value (a text in UTF-8, 64 MB at most; the server limit is often 1 MB) - String - required
    json_params:   The parameters: ttl (seconds, 0 = no expiry, 2592000 = 30 days at most), flags (an integer of 32 bits kept with the value) - String - required
admin
memcached add "{\"host\": \"127.0.0.1\"}" "lock:import" "worker-1" "{\"ttl\": 30}"
mentdb
1

memcached replace <config> <key> <value>


Description

    Store only if the key exists. Returns 1, or 0 if it does not exist

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    value:   The value (a text in UTF-8, 64 MB at most; the server limit is often 1 MB) - String - required
admin
memcached replace "{\"host\": \"127.0.0.1\"}" "nothing" "x"
mentdb
0

memcached replace <config> <key> <value> <json_params>


Description

    Replace with parameters

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    value:   The value (a text in UTF-8, 64 MB at most; the server limit is often 1 MB) - String - required
    json_params:   The parameters: ttl (seconds, 0 = no expiry, 2592000 = 30 days at most), flags (an integer of 32 bits kept with the value) - String - required
admin
memcached replace "{\"host\": \"127.0.0.1\"}" "greeting" "hello" "{\"ttl\": 60}"
mentdb
1

memcached append <config> <key> <value>


Description

    Add a text at the end of an existing value. Returns 1, or 0 if the key does not exist

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    value:   The value (a text in UTF-8, 64 MB at most; the server limit is often 1 MB) - String - required
admin
memcached append "{\"host\": \"127.0.0.1\"}" "greeting" " world"
mentdb
1

memcached prepend <config> <key> <value>


Description

    Add a text at the start of an existing value. Returns 1, or 0 if the key does not exist

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    value:   The value (a text in UTF-8, 64 MB at most; the server limit is often 1 MB) - String - required
admin
memcached prepend "{\"host\": \"127.0.0.1\"}" "greeting" ">> "
mentdb
1

memcached gets <config> <key>


Description

    Read a value with its flags and its cas number: {value, flags, cas}; null if absent

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
admin
memcached gets "{\"host\": \"127.0.0.1\"}" "session:42"
mentdb
{"value": "{\"user\": \"zoe\"}", "flags": 1, "cas": "4"}

memcached cas <config> <key> <value> <cas>


Description

    Store only if nobody changed the value since memcached gets (check and set). Returns STORED, EXISTS (changed by another client) or NOT_FOUND

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    value:   The value (a text in UTF-8, 64 MB at most; the server limit is often 1 MB) - String - required
    cas:   The cas number given by memcached gets - String - required
admin
memcached cas "{\"host\": \"127.0.0.1\"}" "session:42" "{}" "1"
mentdb
EXISTS

memcached cas <config> <key> <value> <cas> <json_params>


Description

    Check and set with parameters (ttl, flags)

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    value:   The value (a text in UTF-8, 64 MB at most; the server limit is often 1 MB) - String - required
    cas:   The cas number - String - required
    json_params:   The parameters: ttl (seconds, 0 = no expiry, 2592000 = 30 days at most), flags (an integer of 32 bits kept with the value) - String - required
admin
memcached cas "{\"host\": \"127.0.0.1\"}" "nothing" "{}" "1" "{\"ttl\": 60}"
mentdb
NOT_FOUND

memcached incr <config> <key>


Description

    Increment an unsigned integer value by 1. Returns the new value, or null if the key does not exist (memcached does not create it)

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
admin
memcached incr "{\"host\": \"127.0.0.1\"}" "visits"
mentdb
11

memcached incr <config> <key> <by>


Description

    Increment by a positive integer (up to 18446744073709551615, it wraps around)

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    by:   The increment - Number - required
admin
memcached incr "{\"host\": \"127.0.0.1\"}" "visits" 5
mentdb
16

memcached decr <config> <key>


Description

    Decrement by 1, never below 0. Returns the new value, or null if the key does not exist

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
admin
memcached decr "{\"host\": \"127.0.0.1\"}" "visits"
mentdb
15

memcached decr <config> <key> <by>


Description

    Decrement by a positive integer, never below 0

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    by:   The decrement - Number - required
admin
memcached decr "{\"host\": \"127.0.0.1\"}" "visits" 100
mentdb
0

memcached touch <config> <key> <ttl>


Description

    Change the time to live of a key without reading it. Returns 1, or 0 if the key does not exist

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
    ttl:   The seconds (0 = no expiry, 2592000 at most) - Number - required
admin
memcached touch "{\"host\": \"127.0.0.1\"}" "session:42" 3600
mentdb
1

memcached delete <config> <key>


Description

    Delete a key. Returns {deleted: 1}, or {deleted: 0} if it did not exist

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    key:   The key: 1 to 250 bytes, no space and no control character - String - required
admin
memcached delete "{\"host\": \"127.0.0.1\"}" "lock:import"
mentdb
{"deleted": 0}

memcached info <config>


Description

    The general statistics of the server (stats) as a JSON object (numbers as numbers)

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
admin
memcached info "{\"host\": \"127.0.0.1\"}"
mentdb
{"pid": 1234, "uptime": 86400, "time": 1795435200, "version": "1.6.39", "curr_connections": 2, "total_connections": 57, "cmd_get": 1200, "cmd_set": 300, "get_hits": 1100, "get_misses": 100, "curr_items": 250, "total_items": 300, "evictions": 0, "bytes": 52000, "limit_maxbytes": 67108864, "threads": 4, "...": "..."}

memcached info <config> <group>


Description

    A group of statistics: items, slabs, settings, sizes or conns

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    group:   The group - String - required
admin
memcached info "{\"host\": \"127.0.0.1\"}" "settings"
mentdb
{"maxbytes": 67108864, "maxconns": 1024, "evictions": "on", "growth_factor": 1.25, "chunk_size": 48, "num_threads": 4, "item_size_max": 1048576, "cas_enabled": "yes", "lru_crawler": "yes", "...": "..."}

memcached flush <config> <json_params>


Description

    Delete every item of the server (all the applications that share it). Needs {"confirm": true}; delay (seconds) makes it happen later. Returns OK

Parameters

    config:   The Memcached configuration as JSON: host (127.0.0.1), port (11211), tls (false; true: certificate and host name checked with the trust store of the JDK), timeout_ms (10000). The text protocol has no authentication: keep the server on a private network - String - required
    json_params:   confirm (must be true), delay (0) - String - required
admin
memcached flush "{\"host\": \"127.0.0.1\"}" "{\"confirm\": true}"
mentdb
OK