PHP code example of wenjy / redis
1. Go to this page and download the library: Download wenjy/redis 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/ */
wenjy / redis example snippets
composer
$config = [
'hostname' => '127.0.0.1',
'port' => 6379,
'database' => 0,
];
$redis = new \EasyRedis\Connection($config);
$redis->set('string_key', 'test_value');
echo $redis->get('string_key');
// lock
$redisLock = new \EasyRedis\Lock($this->redis);
$lockName = 'test';
$identifier = $redisLock->acquireLock($lockName);
// code...
$redisLock->releaseLock($lockName, $identifier);
$semname = 'semaphore:remote';
$identifier = $redisLock->acquireSemaphoreWithLock($semname, 5);
// code...
$res = $redisLock->releaseFairSemaphore($semname, $identifier);