/** |
02 | * 生成自增长数字 |
03 | * |
04 | * @param string $key 缓存key |
05 | * @param int $step 自增长步长 |
06 | * @param int $expires 缓存过期时间,单位秒 |
07 | * |
08 | * @return int $num; |
09 | * @author leeyi <leeyisoft@qq.com> |
10 | */ |
11 | function incr_num( $key = 'ddg' , $step = 1, $expires = 0) { |
12 | $redis = new \\Org\\DDG\\Redis(); |
13 | $cache_key = 'incrnum:' . $key . '_setp:' . $step ; |
14 | $num = $redis ->handler->incrBy( $cache_key , (int) $step ); |
15 | |
16 | if ( $expires >0) { |
17 | $pexpire = 'pexpire' ; |
18 | $millisecond = $expires *1000; |
19 | } else { |
20 | $pexpire = 'pexpireAt' ; |
21 | $millisecond = get_time_235959()*1000+999; |
22 | } |
23 | if (2> $num ) { |
24 | $redis ->handler-> $pexpire ( $cache_key , $millisecond ); // 设置过期时间 |
25 | } |
26 | |
27 | return $num ; |
28 | } |
29 | |
30 | |
31 | /** |
32 | * 根据给定时间戳,获取当天时间最后一秒的时间戳 |
33 | * @author leeyi <leeyisoft@qq.com> |
34 | */ |
35 | function get_time_235959( $time = '' ) { |
36 | $time = empty ( $time ) ? NOW_TIME : intval ( $time ); |
37 | return strtotime ( date ( 'Y-m-d 00:00:00' , $time +86400))-1; |
38 | } |
文章来源:北大青鸟学校开发小组