PassingGrade          string    `json:"passing\_grade" gorm:"not null;comment:及格分"`
ExamDuration          string    `json:"exam\_duration" gorm:"not null;comment:考试时长"`
NumberOfPoints        string    `json:"number\_of\_points" gorm:"comment:积分数量"`
MinimumSubmissionTime string    `json:"minimum\_submission\_time" gorm:"comment:最低交卷时长"`
NotesOnExam           string    `json:"notes\_on\_exam" gorm:"comment:考前注意事项"`
Password              string    `json:"password" gorm:"comment:口令密码"`
State                 string    `json:"state" gorm:"default:正常;comment:状态"`
ExamState             string    `json:"exam\_state" gorm:"index;comment:考试状态"`
ExamPermissionDetail  string    `json:"exam\_permission\_detail" gorm:"comment:考试权限"`   
ExamTimeStart         time.Time `json:"exam\_time\_start" gorm:"index;comment:考试开始时间"`
ExamTimeEnd           time.Time `json:"exam\_time\_end" gorm:"index;comment:考试结束时间"`
LimitExamTime         bool      `json:"limit\_exam\_time" gorm:"comment:限制考试时间"`
ExamTypeID            uint      `json:"exam\_type\_id" gorm:"not null;comment:考试类型"`
TotalScore            uint      `json:"total\_score" gorm:"comment:考试总分"`
SysUserID             uint      `json:"sys\_user\_id" gorm:"comment:指定人员Id"`
ExamCreatedBy         uint      `json:"exam\_created\_by" gorm:"comment:考试创建人"`
ExamPaperID           uint      `json:"exam\_paper\_id" gorm:"comment:试卷Id"`
DeptID                uint      `json:"dept\_id" gorm:"comment:考试所属部门"`
ExamPaper             ExamPaper `json:"exam\_paper" `

}

### 将考试基本信息以及试卷信息存入Redis
var ExamId uint
global.GVA_DB.Model(&exam.Exam{}).Select("id").Find(&ExamId)
var ExamInfo exam.Exam
//准备将查到的ExamInfo存入Redis中
global.GVA_DB.Model(&exam.Exam{}).Where("id = ?", ExamId).First(&ExamInfo)
// 过期时间=这场考试的开始时间-这场考试的结束时间
passingDuration := ExamInfo.ExamTimeEnd.Sub(ExamInfo.ExamTimeStart)
//将要存入redis的结构体序列化一下
jsonExamInfo, _ := json.Marshal(ExamInfo) 
//使用Hash数据结构存入结构体
err = global.GVA_REDIS.HSet(c, "ExamInfo", string(ExamId), jsonExamInfo).Err()
if err != nil {
	return errors2.New("考试信息加入Redis缓存失败")
}
// 给存入redis的hash元素加入过期时间
global.GVA_REDIS.Expire(c, "ExamInfo:string(ExamId)", passingDuration)
### 存入redis的核心代码


1. 先将结构体序列化

var ExamInfo exam.Exam
jsonExamInfo, _ := json.Marshal(ExamInfo)

2. 使用hash数据结构存储结构体(key:“ExamInfo”,field: string(ExamId), value:jsonExamInfo)

err = global.GVA_REDIS.HSet(c, “ExamInfo”, string(ExamId), jsonExamInfo).Err()

### 把结构体从redis中取出


1.先从redis中取出来数据