mirror of
https://github.com/elyby/accounts.git
synced 2024-11-19 19:53:08 +05:30
5f07834f45
Обновлена логика в компонентах для работы с ключами redis
47 lines
1.0 KiB
PHP
47 lines
1.0 KiB
PHP
<?php
|
|
namespace common\components\Redis;
|
|
|
|
use ArrayIterator;
|
|
use IteratorAggregate;
|
|
|
|
class Set extends Key implements IteratorAggregate {
|
|
|
|
public function add($value) {
|
|
$this->getRedis()->sadd($this->key, $value);
|
|
return $this;
|
|
}
|
|
|
|
public function remove($value) {
|
|
$this->getRedis()->srem($this->key, $value);
|
|
return $this;
|
|
}
|
|
|
|
public function members() {
|
|
return $this->getRedis()->smembers($this->key);
|
|
}
|
|
|
|
public function getValue() {
|
|
return $this->members();
|
|
}
|
|
|
|
public function exists(string $value = null) : bool {
|
|
if ($value === null) {
|
|
return parent::exists();
|
|
} else {
|
|
return (bool)$this->getRedis()->sismember($this->key, $value);
|
|
}
|
|
}
|
|
|
|
public function diff(array $sets) {
|
|
return $this->getRedis()->sdiff([$this->key, implode(' ', $sets)]);
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function getIterator() {
|
|
return new ArrayIterator($this->members());
|
|
}
|
|
|
|
}
|