Memcached expire setting error caused by set (Key,exp,value) is true and get (key) is null

Source: Internet
Author: User
Tags memcached
Memcached expire setting error caused by set (Key,exp,value) is true and get (key) is nullTags: memcachednull cache system UNIX Database server 2011-12-10 15:18 17791 people read reviews (1) Favorites Report Category: Web (35)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The recent project used to memcached, and the client chose xmemcached, when setting the expiration time, because of memcached unfamiliar, will be expire set to 1000000000, the intention is to indicate that the longest time do not expire, but in the test found that, The Memcachedclient.set (key,exp,value) result returns true, which means that the item has been successfully cached, but always returns NULL when calling Memcachedclient.get (key), initially assuming that Key's generation strategy was incorrect, Later when the exp filled a 1000, memcached's set and get method all return True, it appears that the problem is expire, so check the following document, found that memcached default expire is 0 means never expires, and this expiration time is 30 days = 30* 24*60*60 = 2.592 million seconds, so the expire is configured to 2.592 million seconds, found that normal execution, in order to test whether the memcached is the longest 30 days, and the value added 1 to 2592001, the same error occurred at this time, set returns True, But get returns NULL, which should reflect 30 of the longest time conjecture. And this time should be memcached itself set, after find memcached source code MEMCACHED.C inside has the following code. Note that the first line #define REALTIME_MAXDELTA 60*60*24*30 is 30 days.

[CPP]  View plain  copy  print? #define  REALTIME_MAXDELTA 60*60*24*30     /*   * given time  value that ' S either unix time or delta from current unix  time, return   * unix time. use the fact that delta  can ' t exceed one month  (And real time value can ' t   *  be that low) .   */   static rel_time_t realtime (const time_t  exptime)  {       /* no. of seconds in 30  days - largest possible delta exptime */           if  (exptime == 0)  return 0; /* 0 means never  expire */          if  (exptime > realtime_maxdelta)  {           /* if  item expiration is at/before the server started, give it an   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;EXPIRATION&NBSP;TIME&NBSP;OF&NBSP;1  second after the server started.               (Because 0 means don ' T expire).   without this,  we ' d             underflow and wrap  around to some large value way in the              future, effectively making items expiring  in the past             really  Expiring never */           if  (exptime <= process_started)                return  (rel_time_t) 1;            return  (rel_time_t) (exptime -  process_started);       } else {            return  (rel_time_t) (exptime + current_time);        }  }   xmemcached is a new Java memcached client. Memcached is a high-performance distributed memory object Key-value caching system for dynamic Web applications to mitigate database load,
Many people now use it as an in-memory database, and memcached interacts with the client through its custom protocols, and Xmemcached is its Java client implementation.

For xmemcached detailed instructions, refer to xmemcached Introduction

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.