PHP code example of drsdre / yii2-redis-counter
1. Go to this page and download the library: Download drsdre/yii2-redis-counter library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
drsdre / yii2-redis-counter example snippets
'components' => [
'redisCounter' => [
'class' => 'drsdre\redis\Counter',
],
...
]
// Create a hourly counter
$counter_key = 'hourly_statistics';
// Check if counter is setup
if (Yii::$app->redisCounter->exists($counter_key)) {
// Atomic increment counter with 1
Yii::$app->redisCounter->incr($counter_key);
} else {
// Create counter set value to 1 and let it exist for 1 hour
Yii::$app->redisCounter->set($counter_key, 1, 60*60);
}
php composer.phar