mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Используем в качестве компонента для соединения с редисом библиотеку Predis
This commit is contained in:
50
common/components/Redis/Set.php
Normal file
50
common/components/Redis/Set.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace common\components\Redis;
|
||||
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
use Yii;
|
||||
|
||||
class Set extends Key implements IteratorAggregate {
|
||||
|
||||
/**
|
||||
* @return Connection
|
||||
*/
|
||||
public static function getDb() {
|
||||
return Yii::$app->redis;
|
||||
}
|
||||
|
||||
public function add($value) {
|
||||
static::getDb()->sadd($this->key, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function remove($value) {
|
||||
static::getDb()->srem($this->key, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function members() {
|
||||
return static::getDb()->smembers($this->key);
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
return $this->members();
|
||||
}
|
||||
|
||||
public function exists($value) {
|
||||
return (bool)static::getDb()->sismember($this->key, $value);
|
||||
}
|
||||
|
||||
public function diff(array $sets) {
|
||||
return static::getDb()->sdiff([$this->key, implode(' ', $sets)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getIterator() {
|
||||
return new ArrayIterator($this->members());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user