12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace app\common\model;
- use think\Model;
- use app\common\library\Redis;
- class ManageKey extends Model
- {
- // 表名
- protected $table = 'manage_key';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- // 追加属性
- protected $append = [
- ];
-
- public function getOneByKey($k){
- $redis = Redis::instance();
- $key = 'K:'.$k;
- if(!$redis->exists($key)){
- $source = $this->field('key,image,content')->where(['key'=>$k])->find();
- if($source){
- $redis->hMset($key,$source->toArray());
- $redis->expire($key,86400*2);
- }
- return $source;
- }else{
- return $redis->hGetAll($key);
- }
- }
- }
|