Basic Operations of memcached
set operation
The set operation in memcached is used to store and update data. It accepts three parameters: key, value, and time-to-live (TTL). TTL refers to the number of seconds within which the data is valid.
set key value ttl
For example:
set user:info 100 1643723900
This example stores a key of user:info with a value of 100 and a TTL of 1 hour (60 minutes).
get operation
The get operation in memcached is used to retrieve data. It accepts two parameters: key and time-to-live (TTL).
get key ttl
For example:
get user:info
This example attempts to retrieve the value for the key user:info.
delete operation
The delete operation in memcached is used to delete data. It accepts one parameter: key.
delete key
For example:
delete user:info
This example deletes the value for the key user:info.
example usage
# set key, value, and ttl
set user:info 100 1643723900
# get key
get user:info
# delete key
delete user:info
Note: TTL is an important parameter because it determines the validity period of the data. Using the correct TTL is one of the key aspects of memcached.