PHP code example of mustafa3264 / lrucache
1. Go to this page and download the library: Download mustafa3264/lrucache 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/ */
mustafa3264 / lrucache example snippets
return [
'redis' => [
'prefix' => 'swooletable:cache:', // redis key前缀
'pool' => 'default', // 使用哪个redis连接池做缓存
'hash_key_length' => 3, // 使用hash做缓存key的默认长度
'expire' => 86400, //缓存默认过期时间
],
];
/**
* @property int $id
* @property string $name 权限名称
* @property string $status 状态:enabled 启用;disabled 禁用;
* @property array $data 权限配置
* @property Carbon $created_time 创建时间
* @property Carbon $updated_time 更新时间
* @property Carbon $deleted_time 删除时间
* @method void setName(string $field)
* @method void setStatus(string $field)
* @method void setData(array $field)
*/
#[SwooleTable(swooleTableSize: 8, lruLimit: 5, hashKeyLength: -1)]
class RoleDaoImpl extends \Hyperf\DbConnection\Model\Model
{
use SoftDeletes;
use Snowflake;
protected ?string $table = 'role';
protected array $fillable = [
'id', 'name', 'status', 'data',
];
protected array $casts = [
'id' => 'integer',
'data' => 'array',
'created_time' => 'datetime',
'updated_time' => 'datetime',
'deleted_time' => 'datetime',
];
public function getField(): array
{
return [];
}
#[SwooleTableCache]
public function getById(int $id): ?RoleDaoImpl
{
return self::query()->find($id);
}
}
$cache = LRUCacheManager::instance('test_table');
$cache->put('test_table:', "8555201", [
'id' => rand(1, 99),
'name' => 'fang',
'age' => 23,
], 86400 * 7);
$cache->get('test_table:', "8555201")
$RNCache = make(RNCacheInterface::class);
//存储
$RNCache->set('aaaaaa:','12222222', [
'id' => 12,
'name' => 'zhongjian',
'age' => 26,
], 86400 * 12);
//获取
$ret = $RNCache->get('aaaaaa:', '12222222');
//删除
$RNCache->del('aaaaaa:', '12222222');
shell
php bin/hyperf.php vendor:publish mustafa3264/lrucache