我使用 golang 作为我的后端。我在 redis 中存储了一些令牌值。我正在设置值 HSET 并在 HGETALL 中获取值。我想知道是否有任何函数可以设置我存储的键的到期时间在 redis 数据库中。我希望令牌及其数据在 1 小时后被删除。我正在为 redis 使用 Redigo 包。谢谢。感谢任何帮助。
I use this to set the struct with has token as key
redisCon.Do("HMSET", redis.Args{}.Add(hashToken).AddFlat(&dataStruct)...)
Run Code Online (Sandbox Code Playgroud) 我将go lang用作后端,将postgreSQL用作数据库。我使用“ github.com/lib/pq”驱动程序来连接数据库。我有一个结构,其中有很多字段,并且里面有一些JSON。
我的结构看起来像这样
ApplyLeave1 struct {
LeaveId int
EmpId string
SupervisorEmpId string
LeaveDays float64
MDays float64
LeaveType string
DayType string
LeaveFrom time.Time
LeaveTo time.Time
AppliedDate time.Time
LeaveStatus string
ResultDate time.Time
Certificate []*CertificateInfo
}
CertificateInfo struct {
Id int64
FileName string
FileType string
FileLocation string
}
Run Code Online (Sandbox Code Playgroud)
该结构很大,内部有一些json数组,我的数据库架构与该结构相同。至于我研究的唯一插入方法是使用查询并从mystruct逐个插入到数据库中,例如这样
var leave ApplyLeave1
db.Exec("INSERT INTO TABLENAME(leaveid,empid,supervisorid,....) VALUES($1,$2,$3,$4,....)",leave.LeaveId,leave.EmpId,leave.SupervisorId,.....)
Run Code Online (Sandbox Code Playgroud)
因为我的结构很大,所以写的时间太长了,是否可以一次插入整个结构,请指导我如何在数据库中插入json数组。感谢任何帮助。
更新信息:
CREATE TABLE IF NOT EXISTS apply_leave1
(
leaveid serial PRIMARY KEY NOT NULL ,
empid varchar(10) NOT NULL …Run Code Online (Sandbox Code Playgroud) 我使用Go作为后端,使用MongoDB作为数据库,并使用beego框架来开发此应用程序。我想在前端进行分页。
我的结构看起来像这样:
type Employee struct {
Name string
EmpId string
Password string
PhoneNumber int32
EmailAddress string
Position string
AccessLevel string
Gender string
MaritalStatus string
Nationality string
Department string
ICNumber string
JoinDate time.Time
ConfirmationDate time.Time
EndDate time.Time
AnnualLeave []*AnnualLeaveInfo
MedicalLeave []*MedicalLeaveInfo
NopayLeave []*NopayLeaveInfo
ChildcareLeave []*ChildcareLeaveInfo
}
type AnnualLeaveInfo struct {
Id int
Days float64
Type string
From time.Time
To time.Time
AppliedDate time.Time
Status string
Certificate []*CertificateInfo
}
Run Code Online (Sandbox Code Playgroud)
其他请假信息与年假信息相同。我想显示所有雇员文档的所有叶子,这些叶子按适用日期和状态排序。现在,我要获取所有休假详细信息,然后追加到数组中,然后使用游标值(在上一个响应中传递到前端的数组的最后检索索引值)并从数组中查找值。我知道这不是一个好函数,因为对于每个请求,它都需要检索所有请假详细信息,以便仅检索前端请求的20个请假详细信息。
追加到数组后的结果是这样的
"0": {
"LeaveEmpId": "rajeshk",
"Name": "rahul",
"LeaveId": 8,
"LeaveType": "annualleave",
"LeaveTotal": 2, …Run Code Online (Sandbox Code Playgroud)