Skip to content

hlhill/psr-cache-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

基于easyswoole Redis客户端的缓存驱动

基于easyswoole Redis客户端实现的遵循PSR-16 CacheInterface的缓存驱动

使用

Config

$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);

set

$key = 'key';
$value = 'value';
$ttl = 600;
$client->set($key, $value, $ttl);

get

$key = 'key';
$default = 'defaultValue';
return $client->get($key, $default);

has

$key = 'key';
return $client->has($key);

delete

$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();

About

easyswoole cache redis driveimplement PSR-16

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages