PHP+redis实现添加处理投票的方法

本文实例讲述了PHP+redis实现添加处理投票的方法分享给大家供大家参考,具体如下:

rush:PHP;"> pconnect('127.0.0.1',6379); if(isset($_SERVER['HTTP_REFERER'])){ $url_md5 = md5($_SERVER['HTTP_REFERER']); } $adve_key = 'adve'; $adve_key_exists = 'adve_exists'; if(!$redis->exists($adve_key_exists)){ $list = $MysqL_obj->fetch_array("select * from admin_online_adve"); if($list){ foreach ($list as $key => $value) { $url_hash = md5($value['adve_url']); $adve_hash_key = $adve_key.":".$url_hash; $id = $value['id']; $redis->set($adve_hash_key,$id); $redis->set($adve_key_exists,true); } } } $adve_new_key = $adve_key.':'.$url_md5; if($redis->exists($adve_new_key)){ $adve_plus = $adve_new_key.":plus" ; if(!$redis->exists($adve_plus)){ $redis->set($adve_plus,1); }else{ $redis->incr($adve_plus); $num = $redis->get($adve_plus); if($num >100){ $id = $redis->get($adve_new_key); // insert to sql; $MysqL_obj->query("update admin_online_adve set adve_num=adve_num+$num where id=$id"); $redis->set($adve_plus,1); } } } } ?> <Meta http-equiv="refresh" content="1;url=https://itunes.apple.com/cn/app/san-guo-zhi15-ba-wangno-da-lu/id694974270?mt=8"> <a href="https://www.jb51.cc/tag/tongji/" target="_blank" class="keywords">统计</a>

其中PHP连接MysqLMysqL.class.PHP如下:

rush:PHP;"> _server = $dbserver; $this->_user = $dbuser; $this->_password = $dbpassword; $this->_dbname = $database; $this->_persistency = $persistency; $this->_autoConnect = $autoConnect; $this->_checkDB = $checkdb; if($autoConnect){ $this->connection(); } } function connection($newLink = false) { if (!$newLink){ if($this->_isConnect && isset($this->_db_connect_id)){ @MysqL_close($this->_db_connect_id); } } $this->_db_connect_id = ($this->persistency) ? @MysqL_pconnect($this->_server,$this->_user,$this->_password):@MysqL_connect($this->_server,$this->_password,$newLink); if ($this->_db_connect_id) { if ($this->version() > '4.1') { if ($this->_charset != "") { @MysqL_query("SET NAMES '".str_replace('-','',$this->_charset)."'",$this->_db_connect_id); } } if ($this->version() > '5.0') { @MysqL_query("SET sql_mode=''",$this->_db_connect_id); } //检测指定数据库是否连接成功 if ($this->_checkDB){ $dbname = MysqL_query('SELECT database()',$this->_db_connect_id); $dbname = MysqL_fetch_array($dbname,MysqL_NUM); $dbname = trim($dbname[0]); }else{ $dbname = ''; } if ($dbname==$this->_dbname || $dbname==''){ if (!@MysqL_select_db($this->_dbname,$this->_db_connect_id)) { @MysqL_close($this->_db_connect_id); $this->_halt("cannot use database " . $this->_dbname); } }else{ if ($this->_checkDB && !$newLink){ $this->connection(true); } } return true; } else { $this->_halt('connect Failed.',false); } } function setCharset($charset){ //$charset = str_replace('-',$charset); $this->_charset = $charset; } function setDebug($isDebug=true){ $this->_isDebug = $isDebug; } function query($sql,$type='') { return $this->_runsql($sql,MysqL_sql_GETDATA,$type); } function execute($sql) { return $this->_runsql($sql,MysqL_sql_EXECUTE,"UNBUFFERED"); } function _runsql($sql,$sqlType=MysqL_sql_GETDATA,$type = '') { if ($type =="UNBUFFERED"){ $this->_result = @MysqL_unbuffered_query($sql,$this->_db_connect_id); }else{ $this->_result = @MysqL_query($sql,$this->_db_connect_id); } //测试模式下保存执行的sql语句 if($this->_isDebug){ $this->_sql[]=$sql; } if ($this->_result) { return $sqlType==MysqL_sql_GETDATA?$this->getNumRows():$this->getAffectedRows(); }else{ $this->_halt("Invalid sql: ".$sql); return false; } } function next($result_type=MysqL_ASSOC) { $this->fetchRow($result_type); return is_array($this->_record); } function f($name) { if(is_array($this->_record)){ return $this->_record[$name]; }else{ return false; } } function fetchRow($result_type=MysqL_ASSOC) { if( $this->_result ) { $this->_record = @MysqL_fetch_array($this->_result,$result_type); return $this->_record; }else{ return false; } } function getAll($sql,$primaryKey="",$result_type=MysqL_ASSOC) { if ($this->_runsql($sql,MysqL_sql_GETDATA)>=0){ return $this->fetchAll($primaryKey,$result_type); }else{ return false; } } function getone($sql,MysqL_sql_GETDATA)>0){ $arr = $this->fetchAll("",$result_type); if(is_array($arr)){ return $arr[0]; } }else{ return false; } } function fetchAll($primaryKey = "",$result_type=MysqL_ASSOC) { if ($this->_result) { $i = 0; $this->_rowset = array(); if ($primaryKey=="") { while($this->next($result_type)) { $this->_rowset[$i] = $this->_record; $i++; } }else{ while($this->next($result_type)) { $this->_rowset[$this->f($primaryKey)] = $this->_record; $i++; } } return $this->_rowset; }else{ //$this->_halt("Invalid Result"); return false; } } function checkExist($sql) { return $this->query($sql)>0?true:false; } function getValue($sql,$colset = 0) { if ($this->query($sql)>0){ $this->next(MysqL_BOTH); return $this->f($colset); }else{ return false; } } function getNumRows() { return @MysqL_num_rows($this->_result); } function getNumFields() { return @MysqL_num_fields($this->_result); } function getFiledname($offset) { return @MysqL_field_name($this->_result,$offset); } function getFiledType($offset) { return @MysqL_field_type($this->_result,$offset); } function getFiledLen($offset) { return @MysqL_field_len($this->_result,$offset); } function getInsertId() { return @MysqL_insert_id($this->_db_connect_id); } function getAffectedRows() { return @MysqL_affected_rows($this->_db_connect_id); } function free_result() { $ret = @MysqL_free_result($this->_result); $this->_result = 0; return $ret; } function version() { return @MysqL_get_server_info($this->_db_connect_id); } function close() { return @MysqL_close($this->_db_connect_id); } function sqlOutput($isOut = true,$all = true){ if($all){ $ret = implode("
",$this->_sql); }else{ $ret = $this->_sql[count($this->_sql)-1]; } if ($isOut){ echo $ret; }else{ return $ret; } } function _halt($msg="Session halted.",$getErr=true) { if($this->_isDebug){ if($getErr){ $this->_errno = @MysqL_errno($this->_db_connect_id); $this->_error = @MysqL_error($this->_db_connect_id); printf("MysqL _error: %s (%s)
/n",$this->_errno,$this->_error); } die($msg); }else{ die("Session halted."); } } } ?>

希望本文所述对大家PHP程序设计有所帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返回预支付订单号的接口,目前微信支付所有场景均使用这一接口。下面介绍的是其中NATIVE的支付实现流程与PC端实现扫码支付流程
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返回预支付订单号的接口,目前微信支付所有场景均使用这一接口。下面介绍的是其中APP的支付的配置与实现流程
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户信息这个功能的开发流程。 配置 1.首先得在微信公众平台申请一下微信小程序账号并获取到小程序的AppID和AppSecret https://mp.weixin.qq.com/cgi-bin/loginpage?url=%2Fwxamp%2F
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一款开源且免费商用的后台开发框架,它基于ThinkPHP和Bootstrap两大主流技术构建的极速后台开发框架,它有着非常完善且强大的功能和便捷的开发体验,使我逐渐喜欢上了它。
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛,就离不开通讯了,然后我就想到了长连接。这里本人用的是GatewayWorker框架。
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返回预支付订单号的接口,目前微信支付所有场景均使用这一接口。下面介绍的是其中JSAPI的支付实现流程
服务器优化必备:深入了解PHP8底层开发原理
Golang的网络编程:如何快速构建高性能的网络应用?
Golang和其他编程语言的对比:为什么它的开发效率更高?
PHP8底层开发原理揭秘:如何利用新特性创建出色的Web应用
将字符重新排列以形成回文(如果可能)在C++中
掌握PHP8底层开发原理和新特性:创建高效可扩展的应用程序
服务器性能优化必学:掌握PHP8底层开发原理
PHP8新特性和底层开发原理详解:优化应用性能的终极指南
将 C/C++ 代码转换为汇编语言
深入研究PHP8底层开发原理:创建高效可扩展的应用程序
C++程序查找法向量和迹
PHP8底层开发原理实战指南:提升服务器效能
重排数组,使得当 i 为偶数时,arr[i] >= arr[j],当 i 为奇数时,arr[i] <= arr[j],其中 j < i,使用 C++ 语言实现
Golang的垃圾回收:为什么它可以减少开发人员的负担?