1、Redis 防治联系点击
header("Content-type:text/html;charset=utf-8"); function Redis (){ $redis = new Redis(); $redis->connect('127.0.0.1','6379') or die("Con not Content Redis"); $redis->auth('123123'); //redis密码 if($redis){ return $redis; }else{ die("Con not Content Redis"); } } $key = 'hua'; $redis = Redis(); if($redis->exists($key)){ //exists查看该键是否存在
echo $redis->get($key); //获取键值 }else{ $redis->set($key,'123'); //给键赋值 $redis->expire($key,5); //给键设置有效时间 echo "敬请期待"; }
2、在一天内允许点击多少次
$key1 = 'hua'.@date('Ymd',time()); if($redis->exists($key1)){ if($redis->get($key1)<3){ $redis->incr($key1); //自增1 // $redis->incrby($key1,2) //设置自增多少 echo $redis->get($key1); }else{ die("每天只能点击三次"); } }else{ $redis->set($key1,0); //默认从0开始 }
keys *
清除所有键值
flushall