2016-02-14 23:20:10 +05:30
|
|
|
<?php
|
2016-11-27 20:11:39 +05:30
|
|
|
namespace common\components\Redis;
|
2016-02-14 23:20:10 +05:30
|
|
|
|
2016-11-27 20:11:39 +05:30
|
|
|
use ArrayIterator;
|
2016-02-14 23:20:10 +05:30
|
|
|
use IteratorAggregate;
|
|
|
|
|
|
|
|
class Set extends Key implements IteratorAggregate {
|
|
|
|
|
|
|
|
public function add($value) {
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->getRedis()->sadd($this->key, $value);
|
2016-02-14 23:20:10 +05:30
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function remove($value) {
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->getRedis()->srem($this->key, $value);
|
2016-02-14 23:20:10 +05:30
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function members() {
|
2016-11-29 04:27:58 +05:30
|
|
|
return $this->getRedis()->smembers($this->key);
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
public function getValue() {
|
|
|
|
return $this->members();
|
|
|
|
}
|
|
|
|
|
2016-11-29 04:27:58 +05:30
|
|
|
public function exists(string $value = null) : bool {
|
|
|
|
if ($value === null) {
|
|
|
|
return parent::exists();
|
|
|
|
} else {
|
|
|
|
return (bool)$this->getRedis()->sismember($this->key, $value);
|
|
|
|
}
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
public function diff(array $sets) {
|
2016-11-29 04:27:58 +05:30
|
|
|
return $this->getRedis()->sdiff([$this->key, implode(' ', $sets)]);
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function getIterator() {
|
2016-11-27 20:11:39 +05:30
|
|
|
return new ArrayIterator($this->members());
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|