postor/yii2-redis-filter

This package is abandoned and no longer maintained. No replacement package was suggested.

ordering,paging,categorizing your items use via sorted set

Installs: 18

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 1

Open Issues: 1

Type:yii2-extension

1.1.1 2020-01-03 12:30 UTC

This package is not auto-updated.

Last update: 2023-04-22 17:28:28 UTC


README

ordering,paging,categorizing your items use via sorted set 利用redis的有序集合实现排序、分页、分类

quick glance: https://www.youtube.com/watch?v=zLYAlfSTUQE&list=PLM1v95K5B1ntVsYvNJIxgRPppngrO_X4s

install安装

php composer.phar require --prefer-dist postor/yii2-redis-filter

config配置

'components' => [
        ....,
        'redis' => [
	        'class' => 'yii\redis\Connection',
	        'hostname' => REDIS_HOST,
	        'port' => REDIS_PORT,
	        'database' => REDIS_DB,
        ],
        'redisfilter'=>[
          'class'=>'postor\redisfilter\RedisFilter',
          'redis'=>'redis',
        ],
        ....

usage使用

\Yii::$app->redisfilter->getTagList($tag,$offset,$limit); $tag param:

  • string, just the tag set 字符串就是对应的tag集合
  • array, deep loop each array and interstore key and value, then unionstore all element results. 数组情况则key与value取交集,然后所有数组元素取并集,可以嵌套

['a','b'=>['c'=>['d','e'=>'f']]] means a|(b&c&(d|(e&f))

//set tags 设置标签
$rf = \Yii::$app->redisfilter;
$rf->setTag($a->id, 'base', $a->created_time); //all article sort by created_time 所有文章按时间排序
$rf->setTag($a->id, 'samsung'); //all article tag into tag sets 所有文章按标签类型贴收入对应集合
$rf->removeTag($b->id, 'base');

//filter tags 筛选标签
//by page 按分页
$ids = $rf->getTagList(['seta','setb'=>'setc'],$offset,$pageSize); // seta|(setb&setc) 
//$ids  array(11) { [0]=> string(7) "1385584" [1]=> string(7) "1385585" [2]=> string(7) "1385586" [3]=> string(7) "1385587" [4]=> string(7) "1385588" [5]=> string(7) "1385589" [6]=> string(7) "1515910" [7]=> string(7) "1515911" [8]=> string(7) "1515912" [9]=> string(7) "1515913" [10]=> string(7) "1515914" }

//by score 按分数
$zsetname = $rf->getZset(['base'=>'samsung']); // base&samsung
$total = $rf->getTagTotalByZset($zsetname);
$ids = $rf->getTagListByScore($zsetname, time()-86400*3, time());


example

cd example

# config your own redis
vi config/web.php

./yii serve

open localhost:8080 and try

for details see codes: example/models/NumberFilter.php