1. 程式人生 > >redis設定零點過期,網站瀏覽量

redis設定零點過期,網站瀏覽量

<?php
/**
*
*瀏覽人數++
*
**/

//引數
$dev_code = $_POST['dev_code'];


if ($dev_code) {
	# code...
	$redis =  new Redis();
	$result = $redis->connect('127.0.0.1',6379);
	//獲取到明天凌晨00的秒
	$times = mktime(23,59,59) - mktime(date('H'),date('i'),date('s'));
	if ($result) {
		# redis密碼
		$redis->auth('admin');
		//門店總數
		$dev_code_total = $redis->get("$dev_code");
		//歷史總人數
		$totals = $redis->get('kftotal');
		//今天認證人數
		 $kfctodaytotal = $redis->get('kfctodaytotal');

		 //門店總認證人數
		 if (!$dev_code_total) {
		 	# code...
		 	$dev_code_total = 0;
		 	$redis->set("$dev_code",1);
		 }else{
		 	$redis->INCR("$dev_code");
		 }

		 //認證總人數
		 if (!$kfctotal) {
		 	# code...
		 	$kfctotal = 0;
		 	$redis->set("kfctotal",1);


		 }else{
		 	$redis->INCR("kfctotal");
		 }

		 //當天認證人數
		 if (!$kfctodaytotal) {
		 	# code...
		 	$todaytotal = 0;
		 	$redis->set("kfctodaytotal",1);
		 	//設定0點過期
		 	$redis->expire('kfctodaytotal',$times);
		 }else{
		 	$redis->INCR("kfctodaytotal");
		 }

	}
}