"Flying the Moon" memcached four important notes (key length, space limit, maximum item)

Source: Internet
Author: User
Tags control characters memcached

1. What is the maximum length of the key value ?

The maximum length of the memcached key is one character .

Note 250 is a limitation within the memcached server-side (can be modified)

If you are using a client that supports "key prefixes" or similar features, then the maximum length of key (prefix + original key) can be more than 250 characters.

We recommend using shorter keys because you can save memory and bandwidth.

Key as long as not repeating on the line, if too big waste memory.

2.key cannot have spaces and control characters

The key must not include control characters or whitespace.

    1. the Item the expiration time limit ?

The expiration time is maximum .

If you do not pay attention to this detail, the Expiration time setting is greater than 30 days, the value will not be set into the cache

    1. the maximum number of individuals that can be stored item?

1MB

If your data is larger than 1MB, consider compressing or splitting the client into multiple keys.

Code support:

If you use the Spy

Net.spy.memcached.util.StringUtils.validateKey (String)

This method is used to verify that the key

Where code:

Java code
  1. public static void Validatekey (String key) {
  2. byte[] keybytes = keyutil.getkeybytes (key);
  3. if (Keybytes.length > Memcachedclientif.max_key_length) {
  4. throw new IllegalArgumentException ("Key is too long (MaxLen ="
  5. + Memcachedclientif.max_key_length + ")");
  6. }
  7. if (Keybytes.length = = 0) {
  8. throw New IllegalArgumentException (
  9. "Key must contain at least one character.");
  10. }
  11. Validate the key
  12. for (byte b:keybytes) {
  13. if (b = = ' | | b = = ' \ n ' | | b = = ' \ r ' | | b = = 0) {
  14. throw New IllegalArgumentException (
  15. "Key contains invalid characters:" "+ Key +" "");
  16. }
  17. }
  18. }

As you can see, the maximum length is 250, the key of length 0 is not allowed,

If there is a space \ r such a control symbol is not allowed

"Flying the Moon" memcached four important notes (key length, space limit, maximum item)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.