Home  >  Article  >  php教程  >  一种简单的php使用redis做缓存的方法,php使用redis缓存

一种简单的php使用redis做缓存的方法,php使用redis缓存

WBOY
WBOYOriginal
2016-06-13 08:55:361157browse

一种简单的php使用redis做缓存的方法,php使用redis缓存

这里介绍的缓存方法比较简单,下面是大概思路

例子:
一个列表缓存例子,由于列表数据实时性要求不高,可以缓存1分钟。


大概思路:
根据请求的url来判断:
1.请求的url hash 后在redis中有记录,则直接返回redis中的数据。
2.请求的url hash 后在redis中无记录,则查询数据库(mysql),保存到redis中,并返回。
url格式: 模块,控制器,操作(action),page


redis缓存的数据格式:
分为两种:
一种是html标签,也就是框架渲染完成的html页面。
另一种是josn数据,这部分是ajax请求所需的数据。

 

@note

使用php开发了5个月,这个思路是我的同事(领导)想出来的,记录一下

20150809

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn