基于easyswoole Redis客户端实现的遵循PSR-16 CacheInterface的缓存驱动
$redisClient = new \EasySwoole\Redis\Redis(new \EasySwoole\Redis\Config\RedisConfig([
'host' => REDIS_HOST,
'port' => REDIS_PORT,
]));
$redisCacheConfig = new \Hlhill\PsrCacheRedis\Config\Config();
$client = new \Hlhill\PsrCacheRedis\RedisCache($redisClient, $redisCacheConfig);
$key = 'key';
$value = 'value';
$ttl = 600;
$client->set($key, $value, $ttl);
$key = 'key';
$default = 'defaultValue';
return $client->get($key, $default);
$key = 'key';
return $client->has($key);
$key = 'key';
return $client->delete($key);
$cache = [
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3',
];
$ttl = 600;
$client->setMultiple($cache, $ttl);
$keys = [
'key1',
'key2',
'key3',
];
$default = 'defaultValue';
return $client->getMultiple($keys, $default);
$keys = [
'key1',
'key2',
'key3',
];
$client->deleteMultiple();
$client->clear();