Javatpoint Logo
Javatpoint Logo

Memcached - Delete Key

Memcached delete command is used to delete an existing key from the Memcached server. It means it removes an item from the cache if it exists.

Syntax

Here,

key: It is the key data stored and retrieved from Memcached.

noreply: It is an optional parameter. It is used to inform the server not to send any reply.

Return Value

This command will return the following value:

DELETED: Means successful deletion.

ERROR: It shows error while deleting data or when the syntax is wrong.

NOT_FOUND: shows that the key does not exist in the Memcached server.

Example in Ubuntu

Let's see an example for the delete command. Here we will use 'city' as the key and store 'bangalore' in it with the expiration of time 900 seconds. After this, delete command is used to delete the key 'city.'

Memcached - Delete Key

Example in Windows:

Memcached Server:

Memcached - Delete Key

Memcached Client:

Memcached - Delete Key

Delete data using Java Application

Let's consider Memcached server is running on host 127.0.0.1 and port 11211. Here, we will use delete() method to delete the data from a Memcached server.

Example 1

Output:

Connection to server successful
set status: true
Get from Cache: Bangalore
Delete from Cache: true
Get from Cache: null

Example 2

Output:

Connection to server successful
set status:true
javatpoint value in cache - largest online tutorials library
delete status:true
javatpoint value in cache - null

Next Topic#





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA