mirror of
https://github.com/elyby/accounts.git
synced 2024-12-26 23:20:18 +05:30
c0aa78d156
Completely removed usage of the RabbitMQ. Queue now based on Redis channels. Worker process now extracted as separate docker container. Base image upgraded to the 1.8.0 version (PHP 7.2.7 and pcntl extension).
48 lines
1.0 KiB
PHP
48 lines
1.0 KiB
PHP
<?php
|
|
namespace common\components\Redis;
|
|
|
|
use ArrayIterator;
|
|
use IteratorAggregate;
|
|
use Yii;
|
|
|
|
class Set extends Key implements IteratorAggregate {
|
|
|
|
public function add($value): self {
|
|
Yii::$app->redis->sadd($this->getKey(), $value);
|
|
return $this;
|
|
}
|
|
|
|
public function remove($value): self {
|
|
Yii::$app->redis->srem($this->getKey(), $value);
|
|
return $this;
|
|
}
|
|
|
|
public function members(): array {
|
|
return Yii::$app->redis->smembers($this->getKey());
|
|
}
|
|
|
|
public function getValue(): array {
|
|
return $this->members();
|
|
}
|
|
|
|
public function exists(string $value = null): bool {
|
|
if ($value === null) {
|
|
return parent::exists();
|
|
}
|
|
|
|
return (bool)Yii::$app->redis->sismember($this->getKey(), $value);
|
|
}
|
|
|
|
public function diff(array $sets): array {
|
|
return Yii::$app->redis->sdiff([$this->getKey(), implode(' ', $sets)]);
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function getIterator() {
|
|
return new ArrayIterator($this->members());
|
|
}
|
|
|
|
}
|