2016-02-14 23:20:10 +05:30
|
|
|
<?php
|
|
|
|
namespace common\components\redis;
|
|
|
|
|
|
|
|
use IteratorAggregate;
|
|
|
|
use Yii;
|
|
|
|
|
|
|
|
class Set extends Key implements IteratorAggregate {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \yii\redis\Connection
|
|
|
|
*/
|
|
|
|
public static function getDb() {
|
2016-07-17 21:43:40 +05:30
|
|
|
return Yii::$app->redis;
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
public function add($value) {
|
|
|
|
$this->getDb()->executeCommand('SADD', [$this->key, $value]);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function remove($value) {
|
|
|
|
$this->getDb()->executeCommand('SREM', [$this->key, $value]);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function members() {
|
|
|
|
return $this->getDb()->executeCommand('SMEMBERS', [$this->key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getValue() {
|
|
|
|
return $this->members();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function exists($value) {
|
|
|
|
return !!$this->getDb()->executeCommand('SISMEMBER', [$this->key, $value]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function diff(array $sets) {
|
|
|
|
return $this->getDb()->executeCommand('SDIFF', [$this->key, implode(' ', $sets)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function getIterator() {
|
|
|
|
return new \ArrayIterator($this->members());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|