我有一个静态方法来执行 find() 并在应用程序启动时将营销活动数据添加到 Redis。
CampaignSchema.statics.activeCampaignsToRedis = function () {
this
.find()
.where('active').equals(true)
...
};
Run Code Online (Sandbox Code Playgroud)
我想添加一个保存后挂钩,每当添加或修改新的营销活动时,该挂钩都会重新运行静态方法来更新 Redis 中的数据。
CampaignSchema.post('save', function (next) {
// call CampaignSchema.statics.activeCampaignsToRedis();
});
Run Code Online (Sandbox Code Playgroud)