memcached expire time 0

今天一个同事问道缓存设置0然后判断永不过期的实现机制是怎么样子的,当时猜想可能是设置了一个比较大的值(比如十年),不过对此不确定。
兴起去pull了memcached的源码来看:

git pull https://github.com/memcached/memcached.git

memcached.c 文件 3314 行:

/*
If exptime is zero realtime() would return zero too, and
realtime(exptime) – 1 would overflow to the max unsigned
value. So we process exptime == 0 the same way we do when
no delay is given at all.
*/
if (exptime > 0)
settings.oldest_live = realtime(exptime) – 1;
else /* exptime == 0 */
settings.oldest_live = current_time – 1;

原来是用了无符号整数的溢出。。。

Resque

在厦门PHPer群里看到的。
这个玩意儿比较好的地方就是可以跟操作系统解耦。
其中用到了redis作为队列处理,依赖还是较强,处理量不大的话,用sqlite来替代会不会更好?。

里面的几个思路跟我自己在cron脚本的一些处理上蛮像,殊途同归,LOL。

Resque: https://github.com/defunkt/resque
PHP的clone:https://github.com/chrisboulton/php-resque

Ref: http://avnpc.com/pages/run-background-task-by-php-resque