Home >Backend Development >PHP Tutorial >实战中redis怎么用

实战中redis怎么用

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:48:41903browse

我们现在网站用到了redis数据库,我虽然也明白那些get set操作,可是最终没有时间过,实战中怎么配合mysql数据库用的尼?


回复讨论(解决方案)

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

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

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

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

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

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

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