Skip to content
Snippets Groups Projects

Resolve #3467120 "Use redis as"

Open tar_inet requested to merge issue/redis-3467120:3467120-use-redis-as into 8.x-1.x
10 files
+ 841
0
Compare changes
  • Side-by-side
  • Inline
Files
10
+ 54
0
<?php
namespace Drupal\redis\KeyValueStore;
use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
class ExpirablePhpRedis extends PhpRedis implements KeyValueStoreExpirableInterface {
/**
* {@inheritdoc}
*/
public function getKey($key = NULL): string {
if (!isset($key)) {
return $this->getPrefix() . ':key-value-expirable:' . $this->collection;
}
else {
return $this->getPrefix() . ':key-value-expirable:' . $this->collection . ':' . $key;
}
}
/**
* {@inheritdoc}
*/
public function setWithExpire($key, $value, $expire) {
return $this->setMultipleWithExpire([$key => $value], $expire);
}
/**
* {@inheritdoc}
*/
public function setWithExpireIfNotExists($key, $value, $expire) {
if (!$this->has($key)) {
return $this->setMultipleWithExpire([$key => $value], $expire);
}
else {
return FALSE;
}
}
/**
* {@inheritdoc}
*/
public function setMultipleWithExpire(array $data, $expire) {
$pipe = $this->client->multi(\Redis::PIPELINE);
foreach ($data as $key => $value) {
$set_key = $this->getKey($key);
$hash = $this->createEntryHash($key, $value);
$pipe->hMset($set_key, $hash);
$pipe->pExpire($set_key, (int) ($expire * 1000));
}
return (bool) $pipe->exec();
}
}
Loading