Redis与网站架构 @joyqi
来源:互联网 发布:linux基础入门ppt 编辑:程序博客网 时间:2024/05/18 02:11
<?php
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$questionid = 123;
$tagids = array(11,22,33);
foreach( $tagids as $sort=>$tagid){
$redis->zAdd('question_tag:'.$questionid,$sort,$tagid);
}
$val = $redis->zRange('question_tag:123',0,-1);
print_r($val);
print_r("\n");[root@localhost redis]# php db2.php
Array
(
[0] => 11
[1] => 22
[2] => 33
)
Redis集合Union操作实现查询$questionTitle = ‘搜索技术’;
$questionId = 123;
$words = fenci($questionTitle); // array(‘搜索’, ‘技术’);
foreach ($words as $word) {
$redis->zAdd(‘w:’ . md5($word), 1, $questionId);
}
// 索引完成
$keywords = ‘怎样实现搜索技术’;
$words = fenci($keywords); // array(‘怎样’, ‘实现’, ‘搜索’, ‘技术’);
$indexes = array_map(function ($word) {
return ‘w:’ . md5($word);
}, $words);
$redis->zUnion(‘result’, $indexes, array_fill(0, count($indexes), 1),
‘sum’);
print_r($redis->zRevRange(‘result’, 0, -1));
- Redis与网站架构 @joyqi
- Redis与网站架构
- 高性能网站架构设计之缓存篇(1)- Redis的安装与使用
- 大型网站架构与分布式架构
- 大型网站架构与分布式架构
- 高性能网站架构设计之缓存篇(7)- Redis哨兵sentinel机制用法与说明
- 【服务器架构】服务器框架与redis
- 浅谈Redis集群的架构与搭建
- 高性能网站架构之缓存篇--Redis安装配置
- 高性能网站架构之缓存篇--Redis安装配置
- SegmentFault 专访 Typecho 发起人:Joyqi
- 网站性能优化与系统架构
- 大型分布式网站架构设计与实践
- 网站架构优化与设计模式
- Drupal与高性能网站架构
- 大型分布式网站架构设计与实践
- 大型分布式网站架构设计与实践
- Magento与大型网站技术架构
- Vue---自定义过滤器
- PHP查询MySQL大量数据的内存占用分析 【转】
- mysql 函数 --ROUND(X) ROUND(X,D)
- Firebug控制台鲜为人知的几种用法[转]
- 中文汉字 转成数字 编码 方法【转】
- Redis与网站架构 @joyqi
- 安装 phpRedisAdmin 笔记
- php使用json_decode返回NULL
- mysql 查看建表时间,表大小
- htmlspecialchars_decode 与 html_entity_decode
- php 函数 object to array
- 获取 头信息函数 apache_request_headers
- dwz封闭当前dailog窗口 【转】
- PHP出现Notice: unserialize(): Error at offset解决方案 【转载】