mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Исправлено поведение при обновлении устаревшего токена
Обновлена логика в компонентах для работы с ключами redis
This commit is contained in:
@@ -9,18 +9,18 @@ class Key {
|
||||
protected $key;
|
||||
|
||||
/**
|
||||
* @return \yii\redis\Connection
|
||||
* @return Connection
|
||||
*/
|
||||
public function getRedis() {
|
||||
return Yii::$app->redis;
|
||||
}
|
||||
|
||||
public function getKey() {
|
||||
public function getKey() : string {
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
return json_decode($this->getRedis()->get($this->key), true);
|
||||
return $this->getRedis()->get($this->key);
|
||||
}
|
||||
|
||||
public function setValue($value) {
|
||||
@@ -29,15 +29,27 @@ class Key {
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->getRedis()->executeCommand('DEL', [$this->key]);
|
||||
$this->getRedis()->del($this->key);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function exists() : bool {
|
||||
return (bool)$this->getRedis()->exists($this->key);
|
||||
}
|
||||
|
||||
public function expire($ttl) {
|
||||
$this->getRedis()->executeCommand('EXPIRE', [$this->key, $ttl]);
|
||||
$this->getRedis()->expire($this->key, $ttl);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __construct(...$key) {
|
||||
if (empty($key)) {
|
||||
throw new InvalidArgumentException('You must specify at least one key.');
|
||||
}
|
||||
|
||||
$this->key = $this->buildKey($key);
|
||||
}
|
||||
|
||||
private function buildKey(array $parts) {
|
||||
$keyParts = [];
|
||||
foreach($parts as $part) {
|
||||
@@ -47,12 +59,4 @@ class Key {
|
||||
return implode(':', $keyParts);
|
||||
}
|
||||
|
||||
public function __construct(...$key) {
|
||||
if (empty($key)) {
|
||||
throw new InvalidArgumentException('You must specify at least one key.');
|
||||
}
|
||||
|
||||
$this->key = $this->buildKey($key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,41 +3,37 @@ 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);
|
||||
$this->getRedis()->sadd($this->key, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function remove($value) {
|
||||
static::getDb()->srem($this->key, $value);
|
||||
$this->getRedis()->srem($this->key, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function members() {
|
||||
return static::getDb()->smembers($this->key);
|
||||
return $this->getRedis()->smembers($this->key);
|
||||
}
|
||||
|
||||
public function getValue() {
|
||||
return $this->members();
|
||||
}
|
||||
|
||||
public function exists($value) {
|
||||
return (bool)static::getDb()->sismember($this->key, $value);
|
||||
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 static::getDb()->sdiff([$this->key, implode(' ', $sets)]);
|
||||
return $this->getRedis()->sdiff([$this->key, implode(' ', $sets)]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user