class PhpRedis in Redis 8
Same name in this branch
- 8 src/Lock/PhpRedis.php \Drupal\redis\Lock\PhpRedis
- 8 src/Flood/PhpRedis.php \Drupal\redis\Flood\PhpRedis
- 8 src/Queue/PhpRedis.php \Drupal\redis\Queue\PhpRedis
- 8 src/Client/PhpRedis.php \Drupal\redis\Client\PhpRedis
- 8 src/Cache/PhpRedis.php \Drupal\redis\Cache\PhpRedis
- 8 src/PersistentLock/PhpRedis.php \Drupal\redis\PersistentLock\PhpRedis
Defines the database flood backend. This is the default Drupal backend.
Hierarchy
- class \Drupal\redis\Flood\PhpRedis implements FloodInterface uses RedisPrefixTrait
Expanded class hierarchy of PhpRedis
1 file declares its use of PhpRedis
- RedisFloodTest.php in tests/
src/ Kernel/ RedisFloodTest.php
4 string references to 'PhpRedis'
- ClientFactory::getClientInterface in src/
ClientFactory.php - Lazy instantiates client proxy depending on the actual configuration.
- PhpRedis::getName in src/
Client/ PhpRedis.php - Get underlying library name used.
- RedisCacheTagsChecksum::doInvalidateTags in src/
Cache/ RedisCacheTagsChecksum.php - Marks cache items with any of the specified tags as invalid.
- RedisTestInterfaceTrait::getRedisInterfaceEnv in tests/
src/ Traits/ RedisTestInterfaceTrait.php - Uses an env variable to set the redis client to use for this test.
File
- src/
Flood/ PhpRedis.php, line 13
Namespace
Drupal\redis\FloodView source
class PhpRedis implements FloodInterface {
use RedisPrefixTrait;
/**
* @var \Redis
*/
protected $client;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* Construct the PhpRedis flood backend.
*
* @param \Drupal\redis\ClientFactory $client_factory
* The database connection which will be used to store the flood event
* information.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack used to retrieve the current request.
*/
public function __construct(ClientFactory $client_factory, RequestStack $request_stack) {
$this->client = $client_factory
->getClient();
$this->requestStack = $request_stack;
}
/**
* {@inheritdoc}
*/
public function register($name, $window = 3600, $identifier = NULL) {
if (!isset($identifier)) {
$identifier = $this->requestStack
->getCurrentRequest()
->getClientIp();
}
$key = $this
->getPrefix() . ':flood:' . $name . ':' . $identifier;
// Add a key for the event to the sorted set, the score is timestamp, so we
// can count them easily.
$this->client
->zAdd($key, $_SERVER['REQUEST_TIME'] + $window, microtime(TRUE));
// Set or update the expiration for the sorted set, it will be removed if
// the newest entry expired.
$this->client
->expire($key, $_SERVER['REQUEST_TIME'] + $window);
}
/**
* {@inheritdoc}
*/
public function clear($name, $identifier = NULL) {
if (!isset($identifier)) {
$identifier = $this->requestStack
->getCurrentRequest()
->getClientIp();
}
$key = $this
->getPrefix() . ':flood:' . $name . ':' . $identifier;
$this->client
->del($key);
}
/**
* {@inheritdoc}
*/
public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL) {
if (!isset($identifier)) {
$identifier = $this->requestStack
->getCurrentRequest()
->getClientIp();
}
$key = $this
->getPrefix() . ':flood:' . $name . ':' . $identifier;
// Count the in the last $window seconds.
$number = $this->client
->zCount($key, $_SERVER['REQUEST_TIME'], 'inf');
return $number < $threshold;
}
/**
* {@inheritdoc}
*/
public function garbageCollection() {
// No garbage collection necessary.
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpRedis:: |
protected | property | ||
PhpRedis:: |
protected | property | The request stack. | |
PhpRedis:: |
public | function |
Makes the flood control mechanism forget an event for the current visitor. Overrides FloodInterface:: |
|
PhpRedis:: |
public | function |
Cleans up expired flood events. This method is called automatically on
cron run. Overrides FloodInterface:: |
|
PhpRedis:: |
public | function |
Checks whether a user is allowed to proceed with the specified event. Overrides FloodInterface:: |
|
PhpRedis:: |
public | function |
Registers an event for the current visitor to the flood control mechanism. Overrides FloodInterface:: |
|
PhpRedis:: |
public | function | Construct the PhpRedis flood backend. | |
RedisPrefixTrait:: |
protected | property | ||
RedisPrefixTrait:: |
protected | function | Get global default prefix | |
RedisPrefixTrait:: |
protected | function | Get prefix | |
RedisPrefixTrait:: |
public | function | Set prefix |