Skip to content
Memcached

add / replace / append / prepend

Escritas condicionais e concatenação de string in-place.

#add#replace#append#prepend

Code

memcached
# add — store ONLY if key does NOT exist
add session:abc 0 600 8
new-user
# STORED  (key was absent)
# NOT_STORED  (key already exists)

# replace — store ONLY if key exists
replace session:abc 0 600 8
returning
# STORED  (key existed)
# NOT_STORED  (key was absent)

# append / prepend — concatenate to existing value (no ttl change)
set greeting 0 0 5
hello
# STORED
append greeting 0 0 6
 world
# STORED
get greeting
# VALUE greeting 0 11
# hello world

# Note: append/prepend do NOT let you change flags or ttl; existing
# flags and ttl are preserved. Use cas to change metadata atomically.