| | |
| | | |
| | | type Cache struct { |
| | | Id uint `gorm:"column:id;primary_key;auto_increment;unique;not null;"` |
| | | Type string `gorm:"column:type;"` // 消息类型 1400, basic |
| | | Data string `gorm:"column:data;type:text"` |
| | | CreateTime int64 `gorm:"column:create_time;"` |
| | | Retry int `gorm:"column:retry;"` |
| | |
| | | } |
| | | |
| | | func (c *Cache) UpdateRetryCount() error { |
| | | return db.Table(c.TableName()).Update("retry", c.Retry+1).Where("id = ?", c.Id).Error |
| | | return db.Table(c.TableName()).Where("id = ?", c.Id).Update("retry", c.Retry+1).Error |
| | | } |
| | | |
| | | func (c *Cache) Delete() error { |
| | | return db.Table(c.TableName()).Where("id = ?", c.Id).Delete(c).Error |
| | | } |
| | | |
| | | func (c *Cache) Clean() error { |
| | | sql := "DELETE FROM caches WHERE id NOT IN (SELECT id FROM caches ORDER BY id DESC LIMIT 15000);" |
| | | return db.Table(c.TableName()).Exec(sql).Error |
| | | } |