php与Redis分页程序代码

用上redis之后速度上去的结果就是操作数据的复杂性了、分页有种脱了裤子放屁的感觉。但是也没有别的办法。代码如下

 

 代码如下 复制代码

<?php
$redis = new Redis;
$redis->connect('127.0.0.1',6379,0);

//数据库
$host='********';
$user='root';
$psd='****';
$dbname='ask';

 

$link = mysql_connect($host,$user,$psd);
mysql_select_db($dbname,$link);
mysql_query("set names utf8");

 

$SQL = "SELECT * FROM question LIMIT 100";
$query = mysql_query($SQL);
$questionName = 'questionName';
while($info = mysql_fetch_array($query)){
$list[] = $info;
$redisName = 'Question_id_'.$info['id'];
$redis->hMset($redisName, $info);
$redis->zAdd($questionName,$info['id'],$info['id']);
$i++;
}
$range = $redis->zRevRange($questionName,0,10); //分页用到的主要函数
foreach($range as $qid){
$pageList[] = $redis->hGetAll('Question_id_'.$qid);
}
print_r($pageList);
?>

 
只是在做例子的时候随便敲敲、完全没有代码规范。请自己封装 基本用上的方法就是Reids的 hMset(),zAdd(), hGetAll(),zRevRange();如有不明白可以查看redis手册,或者与松林讨论。

时间: 2024-07-31 03:58:46

php与Redis分页程序代码的相关文章

jsp 分页程序代码

jsp 分页程序代码 <%  String s;  String theurl;  theurl="products.jsp?";  s=request.getParameter("s");  if(s!=null){   s=new String(request.getParameter("s").getBytes("iso-8859-1"));   theurl="products.jsp?s="

php ajax分页程序代码(1/5)

 代码如下 复制代码 <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv=&qu

JAVA Web项目中用到Redis的代码调试

在项目开发中用到了Redis,需要调试输出数据的正确性, 方法一:修改代码,暂时不从Redis取数据 方法二:清除Redis数据库中的所有key 登录Redis服务器,切换目录到Redis的目录: cd /opt/redis-2.8.13/src/ 清除Redis数据库中的所有key ./redis-cli flushall 作者:csdn博客 微wx笑 更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Java/

asp中&amp;quot;无限流&amp;quot;分页程序代码_应用技巧

<% '****************************************************************** '** 本程序名:"无限流"分页程序 '** 作者:Arbiter(AAsx) '** 版本:Million Level '** '** QQ:22222xx '** Email:Arbiter@21cn.com '** http://www.imagecity.org/ '*********************************

30个php操作redis常用方法代码例子_php实例

 redis的操作很多的,以前看到一个比较全的博客,但是现在找不到了.查个东西搜半天,下面整理一下php处理redis的例子,个人觉得常用一些例子.下面的例子都是基于php-redis这个扩展的. 1,connect 描述:实例连接到一个Redis. 参数:host: string,port: int 返回值:BOOL 成功返回:TRUE;失败返回:FALSE 示例: 复制代码 代码如下: <?php  $redis = new redis();  $result = $redis->conn

二个php分页程序代码

有了这两个参数就可以很方便的写出分页程序,我们以MySql数据库作为数据源,在mysql里如果要想取出表内某段特定内容可以使用的 T-SQL语句:select * from table limit offset,rows来实现.这里的offset是记录偏移量,它的计算方法是offset=$pagesize*($page-1),rows是要显示的记录条数,这里就是$page.也就是说select * from table limit 10,10这条语句的意思是取出表里从第11条记录开始的20条记录

asp中&quot;无限流&quot;分页程序代码

<% '****************************************************************** '** 本程序名:"无限流"分页程序 '** 作者:Arbiter(AAsx) '** 版本:Million Level '** '** QQ:22222xx '** Email:Arbiter@21cn.com '** http://www.imagecity.org/ '*********************************

php+smarty模板分页程序代码

功能比较全的小分页,传几个参数上去就行,计算后输出数组,没什么新意,无非增加了个缩短页码,结果都给压到一个数组,方便输出和调用..附一个smarty的输出样例-.  代码如下 复制代码 /**  * 分页,公共方法  * @param int $page     当前页  * @param int $size     数据条数  * @param int $count    总记录数  * @return mixed 页码数组 ('当前页',上一页','下一页','首页','末页','页码')

Redis——java代码读写redis

一,简单Jedis读写       Jedis jedis=new Jedis("127.0.0.1",6379);//连接的是我本地的服务 System.out.println("成功连接到服务器=="); /*存取string类型*/ jedis.set("name", "lhc"); model.addAttribute("name",jedis.get("name")); /*存