1. Go to this page and download the library: Download mfonte/redisw 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/ */
mfonte / redisw example snippets
use Mfonte\Redisw\Exception\RedisException;
use Mfonte\Redisw\Exception\RedisKeyNotFoundException;
use Mfonte\Redisw\RedisClient;
$client = RedisClient::instance([
'host' => '127.0.0.1',
'port' => 6379,
'serializer' => 'igbinary',
'cache_ttl' => 300,
]);
// no connection is opened until the first command
$client->set('user:42', ['name' => 'Ada', 'admin' => true]);
try {
$user = $client->get('user:42');
} catch (RedisKeyNotFoundException) {
$user = null; // the key does not exist (or has expired)
} catch (RedisException $e) {
// connection or server error
}
// don't want exceptions? wrap() returns null instead
$user = $client->wrap('get', 'user:42');
$client->set('session:abc', $data, 3600); // expires in exactly 1 hour (no jitter)
$client->set('config', $config, 0); // never expires
$client->mset(['a' => 1, 'b' => 2], 120); // same TTL for every key
use Mfonte\Redisw\Cache\SimpleCache;
$cache = new SimpleCache($client); // a Psr\SimpleCache\CacheInterface
$cache->set('user.42', $user, new DateInterval('PT10M'));
$user = $cache->get('user.42', default: null);