1234567891011121314151617181920212223242526272829303132 |
- <?php
- namespace app\common\model;
- use think\Model;
- use app\common\Redis;
- use think\facade\Config;
- /**
- * Description of RedisBaseModel
- *
- * @author sgq
- */
- class RedisBaseModel extends Model {
- protected static function onAfterWrite(Model $model): void {
- $data = $model->toArray();
- if ($data["id"]) {
- $redis = Redis::instance(Config::get("cache.stores.redis.select"));
- $redis->hSet($model->name, $data["id"], json_encode($data));
- }
- }
- protected static function onAfterDelete(Model $model): void {
- $data = $model->toArray();
- if ($data["id"]) {
- $redis = Redis::instance(Config::get("cache.stores.redis.select"));
- $redis->hDel($model->name, $data["id"]);
- }
- }
- }
|