memcached :- Commands

Background

Wanted to list out a couple of memcached commands.

Outline

  1. Version
    • Get’s the Server Version Number
  2. Set
    • Add or overwrite the Key’s value
  3. Get
    • Get the value of the Key
  4. stats slabs
    • Gets physical metrics on allocated slabs
  5. Stats Items
    • Gets object metrics on allocated slabs
  6. Stats Cachedump
    • Lists the items in a slab

Tasks

Version

Outline

Command Payload

  1. Version

Syntax

Version

Output

Textual


VERSION 1.4.5_4_gaa7839e

Image

version.01.20200122.1004PM

Set

Outline

Command Payload

  1. key: It is the key to the data stored and retrieved from Memcached.
  2. flags: It is the 32-bit unsigned integer that the server stores with the data (provided by the user), and returns along with the data when the item is retrieved.
  3. exptime: exptime is expiration time in seconds. 0 means no delay. If it is more than 30 days, Memcached uses it as UNIX timestamp for expiration.
  4. bytes: It is the number of bytes in the data block that needs to be stored. This is the length of the data that is stored in Memcached.
  5. noreply: It is an optional parameter. It is used to inform the server not to send any reply.
  6. value: It is the data that have to be stored. The data needs to be passed on the new line after executing the command with the above options.

Return Value

This command will return the following values :-

  1. STORED: STORED means success
  2. ERROR: ERROR means incorrect syntax or error while saving data.

Sample

Sample – Bangalore

Outline
  1. We are gonna issue the command “set city 0 0 9”
    • set
      • Set a value
    • city
      • key
    • flag
      • 0
        • unsigned integer
    • expirytime
      • 0
        • 0 => Never expiry
    • bytes
      • Bytes size
        • In our case we entered 9
        • 9 is the length of the value we will be entering
        • That value is Bangalore
  2. Once the command is entered and the Enter key is pressed, please enter the value
Command
  1. Input
    • set city 0 0 9
    • Bangalore
  2. Output
    • STORED

Sample – Dell

  1. Input
    • set manufacturer_01 0 0 4
    • Dell
  2. Output
    • STORED

Get

Outline

Command Payload

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

Return Value

This command will return the following values :-

  1. STORED: STORED means success
  2. ERROR: ERROR means incorrect syntax or error while saving data.

Sample

Sample – Bangalore

Outline
  1. We are gonna issue the command “get city”
    • get
      • Get the current value for the key
  2. Once the command is entered, the system returns the key, its metadata and current value
    • VALUE <key> <id> <value>
    • Actual Value
    • END
Command
  1. Input
    • get city
  2. Output
    • Bangalore

Sample – city

Text
  1. Input
    • get city
  2. Output
    • VALUE city 0 9
      Bangalore
      END
Image

20200123.0246PM.01.city.PNG

 

stats slabs

Outline

  1. get_hits
    • Number of successful gets
  2.  cmd_set
    • Number of successful set operations
  3. del_hits
    • Number of key removals
  4. active slabs
    • Number of active slabs

Command Payload

  1. Stats slabs

Syntax


stats slabs

Sample


stats slabs

Output

Image

statsslabs.01.20200122.1048PM

Textual
stats slabs
STAT 1:chunk_size 96
STAT 1:chunks_per_page 10922
STAT 1:total_pages 1
STAT 1:total_chunks 10922
STAT 1:used_chunks 5
STAT 1:free_chunks 0
STAT 1:free_chunks_end 10917
STAT 1:mem_requested 409
STAT 1:get_hits 7
STAT 1:cmd_set 18
STAT 1:delete_hits 0
STAT 1:incr_hits 0
STAT 1:decr_hits 0
STAT 1:cas_hits 0
STAT 1:cas_badval 0
STAT active_slabs 1
STAT total_malloced 1048512
END

stats items

Outline

  1. number
    • Number of items in slab
  2. age
    • Age of Slab ( in seconds )
      • In our case 34710
        • 34710 => 34710  seconds
        • 34710 /60 => 578.5 Minutes
        • 3710/3600 = 9.6 hours
  3. evicted
    • Number of entries removed from slab since slab inception
  4. outofmemory
    • Number of out memory errors occurrences
  5. tailrepairs
  6. reclaimed

Command Payload

  1. Stats Items

Syntax


stats items

Sample


stats items

Output

Image

statsitems.01.20200122.1016PM

Textual

stats items
STAT items:1:number 5
STAT items:1:age 34710
STAT items:1:evicted 0
STAT items:1:evicted_nonzero 0
STAT items:1:evicted_time 0
STAT items:1:outofmemory 0
STAT items:1:tailrepairs 0
STAT items:1:reclaimed 1
END

stats cachedump

Outline

  1. Dumps Items

Command Payload

  1. Stats cachedump
    • slab
      • Slab Number
    • Number of keys to dump

Syntax


stats cachedump [slab], [number-of-keys-to-dump]

Sample


stats cachedump 1, 5

Output

Image

statscachedump.01.20200122.1042PM

Text

ITEM manufacturer_02 [2 b; 1579701232 s]
ITEM manufacturer_01 [4 b; 1579701232 s]
ITEM greeting [11 b; 1579701232 s]
ITEM country [2 b; 1579701232 s]
ITEM city [9 b; 1579701232 s]
END

References

  1. javaTpoint
    • Memcached – Set Data
      Link

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s