/** * 生成自增长数字 * * @param string $key 缓存key * @param int $step 自增长步长 * @param int $expires 缓存过期时间,单位秒 * * @return int $num; * @author leeyi leeyisoft@qq.com */function incr_num($key = 'ddg', $s
/** * 生成自增长数字 * * @param string $key 缓存key * @param int $step 自增长步长 * @param int $expires 缓存过期时间,单位秒 * * @return int $num; * @author leeyi <leeyisoft@qq.com> */ function incr_num($key = 'ddg', $step = 1, $expires = 0) { $redis = new \\Org\\DDG\\Redis(); $cache_key = 'incrnum:'.$key.'_setp:'.$step; $num = $redis->handler->incrBy($cache_key, (int)$step); if ($expires>0) { $pexpire = 'pexpire'; $millisecond = $expires*1000; } else { $pexpire = 'pexpireAt'; $millisecond = get_time_235959()*1000+999; } if (2>$num) { $redis->handler->$pexpire($cache_key, $millisecond); // 设置过期时间 } return $num; } /** * 根据给定时间戳,获取当天时间最后一秒的时间戳 * @author leeyi <leeyisoft@qq.com> */ function get_time_235959($time = '') { $time = empty($time) ? NOW_TIME : intval($time); return strtotime(date('Y-m-d 00:00:00', $time+86400))-1; }