WechatAb.php 1019 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Created by: PhpStorm
  4. * User: lytian
  5. * Date: 2019/11/19
  6. * Time: 14:51
  7. */
  8. namespace app\common\model;
  9. use app\common\library\Redis;
  10. use think\Model;
  11. class WechatAb extends Model
  12. {
  13. // 表名
  14. protected $table = 'wechat_ab';
  15. // 自动写入时间戳字段
  16. protected $autoWriteTimestamp = 'int';
  17. // 定义时间戳字段名
  18. protected $createTime = 'createtime';
  19. protected $updateTime = 'updatetime';
  20. public function getInfo($id)
  21. {
  22. $redisKey = 'WAB:'.$id;
  23. $data = Redis::instance()->hGetAll($redisKey);
  24. if (!$data) {
  25. $row = $this->where('id', 'eq', $id)->find();
  26. if ($row) {
  27. $data = $row->toArray();
  28. Redis::instance()->hMSet($redisKey, $data);
  29. Redis::instance()->expire($redisKey, 600);
  30. }
  31. }
  32. return $data;
  33. }
  34. public function delRedis($id)
  35. {
  36. $redisKey = 'WAB:'.$id;
  37. return Redis::instance()->del($redisKey);
  38. }
  39. }