提交 687510c1 authored 作者: qhz's avatar qhz

【开发】提交代码

上级 010f5e08
# common-cache-sdk # common-cache-sdk
公共缓存sdk
\ No newline at end of file
{
"name": "ydd-open/CommonCacheSdk",
"require": {
"php": ">=7"
},
"autoload": {
"psr-4": {
"CommonCacheSdk\\": "src"
}
}
}
\ No newline at end of file
<?php declare(strict_types=1);
namespace CommonCacheSdk;
class BrandShardingCache
{
protected $cache;
private $key = 'BrandSharding';
private static $instance = null;
public static function getInstance($driver)
{
if (empty(self::$instance)) {
self::$instance = new self($driver);
}
return self::$instance;
}
public function __construct($driver)
{
$this->cache = $driver;
}
public function setBrandShardingCache($brandId, $value)
{
return $this->cache->hset($this->key, (string) $brandId, $value);
}
public function getBrandShardingCache($brandId)
{
return $this->cache->hget($this->key, (string)$brandId);
}
public function getTableName($brandId, $tkey)
{
$isExist = $this->existsBrandShardingCache($brandId);
if (!$isExist) {
return '';
}
$info = $this->getBrandShardingCache($brandId);
$info = $info ? json_decode($info, true) : [];
if (!isset($info[$tkey])) {
return '';
}
return $info[$tkey]['t'];
}
public function existsBrandShardingCache($brandId)
{
$isExist = $this->cache->hExists($this->key, (string)$brandId);
return $isExist ? true : false;
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论