edit-icon download-icon

Use telnet to access ApsaraDB for Memcache

Last Updated: Dec 19, 2017
  1. Enable Memcache password-free logon. Otherwise, authentication is also required for telnet.

    Log on to the Memcache console, and navigate to Management > Password-Free Access Settings. Enter Memcache password for verification. Select an appropriate ECS server, and click Enable to enable password-free access.

  2. Perform telnet access on the ECS server with password-free access enabled.

    1. telnet xxxx.m.cnqdalicm9pub001.ocs.aliyuncs.com 11211
  3. You can store keys directly by using the set and get commands.

Syntax of several common operations is described as follows.

Detailed descriptions of parameters:

  • Common parameters include set, get, add, and replace.

    • set: Adds data if no data exists, and overwrites data if data already exists.

    • get: Obtains the stored data.

    • add: Adds data if no data exists, and terminates operation if data already exists.

    • replace: Terminates operation if no data exists, and replaces data if data exists.

  • The key to store data is a 16-bit unsigned integer (in decimal form).

    This sign is stored along with the data to be stored and be returned when the get command is executed by the client. You can use this sign for special purposes, and this sign is transparent to servers.

  • Expiration time.

    • 0 indicates that the stored data never expires (but can be replaced by server algorithms such as LRU).
    • A non-zero value (unix time) indicates that the stored data never gets obtained by users after expiration (according to the server time).
  • The number of bytes (excluding \r\n at the end) to be stored. When you want to store null data, its value can be 0.

  • Append \r\n (the return key) by the client as the end sign of the command header.

  • Data content.

    Send data blocks (namely the data content to be stored) after the command header ends, and then append \r\n (the return key) as the end of the current communication.

A few examples are as follows:

  1. set hello 0 0 5
  2. world
  3. STORED
  4. //Store "hello" as the key, which never expires. Also, the size of the data "world" is 5 bytes.
  5. get hello
  6. VALUE hello 0 5
  7. world
  8. END
  9. //"get" the stored data.

  1. //Please note that an exception occurs in the event of data mismatch.
  2. set hello 0 0 5
  3. worldhahah
  4. STORED
  5. CLIENT_ERROR NOT SUPPORT COMMAND OR INVALID ARGS NUMBER
  6. //From this you can see that the size of the stored data is 5 bytes while that of the actual content is more than 5 bytes.
  7. get hello
  8. VALUE hello 0 5
  9. world
  10. END
  11. get
  12. //Only 5 bytes of content is actually stored.

  1. delete hello 0
  2. DELETED
  3. //Deletion succeeded.
  4. delete hello 0
  5. NOT_FOUND
  6. //Deletion failed as the key does not exist.

Thank you! We've received your feedback.