ManageKey.php 893 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use app\common\library\Redis;
  5. class ManageKey extends Model
  6. {
  7. // 表名
  8. protected $table = 'manage_key';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. // 追加属性
  15. protected $append = [
  16. ];
  17. public function getOneByKey($k){
  18. $redis = Redis::instance();
  19. $key = 'K:'.$k;
  20. if(!$redis->exists($key)){
  21. $source = $this->field('key,image,content')->where(['key'=>$k])->find();
  22. if($source){
  23. $redis->hMset($key,$source->toArray());
  24. $redis->expire($key,86400*2);
  25. }
  26. return $source;
  27. }else{
  28. return $redis->hGetAll($key);
  29. }
  30. }
  31. }