实战中redis如何用

WBOY
Release: 2016-06-13 12:06:54
Original
872 people have browsed it

实战中redis怎么用
我们现在网站用到了redis数据库,我虽然也明白那些get set操作,可是最终没有时间过,实战中怎么配合mysql数据库用的尼?
------解决思路----------------------
把查询的结果集压缩之后保存 

<br />if ($redis->get('key')){<br />$result = $redis->get('key');<br />$result = unserialize($result);<br />}else{<br />//查询数据库<br />$result = mysql_query($sql);<br />while($row = mysql_fetch_array()){<br />    $arr[] = $row;<br />}<br />$arr = serialize($arr);<br />$redis->set('key',$arr);<br />}<br />
Copy after login
Copy after login

------解决思路----------------------
不是说 redis 优于 memcache 吗?
那么 memcache 可以直接存储 php 的数组和对象,为何 redis 不可以呢?

引用:
把查询的结果集压缩之后保存

<br />if ($redis->get('key')){<br />$result = $redis->get('key');<br />$result = unserialize($result);<br />}else{<br />//查询数据库<br />$result = mysql_query($sql);<br />while($row = mysql_fetch_array()){<br />    $arr[] = $row;<br />}<br />$arr = serialize($arr);<br />$redis->set('key',$arr);<br />}<br />
Copy after login
Copy after login

------解决思路----------------------
redis里包括String、List、Set、Zset、Hash数据类型,看你的数据在应用场景了,mc与redis都可以做为缓存来应用,从mysql取出数据后,就看mc或redis的应用了

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template