mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-13 12:33:47 +08:00
Merge pull request #7 from yuanshuli11/feature/changeGetTTL
对set时过期时间策略的修改
This commit is contained in:
@@ -121,21 +121,27 @@ func Set(db *DB, args [][]byte) redis.Reply {
|
|||||||
case updatePolicy:
|
case updatePolicy:
|
||||||
result = db.PutIfExists(key, entity)
|
result = db.PutIfExists(key, entity)
|
||||||
}
|
}
|
||||||
if result > 0 {
|
/*
|
||||||
if ttl != unlimitedTTL {
|
* 如果设置了ttl 则以最新的ttl为准
|
||||||
expireTime := time.Now().Add(time.Duration(ttl) * time.Millisecond)
|
* 如果没有设置ttl 是新增key的情况,不设置ttl。
|
||||||
db.Expire(key, expireTime)
|
* 如果没有设置ttl 且已存在key的 不修改ttl 但需要增加aof
|
||||||
db.AddAof(reply.MakeMultiBulkReply([][]byte{
|
*/
|
||||||
[]byte("SET"),
|
if ttl != unlimitedTTL {
|
||||||
args[0],
|
expireTime := time.Now().Add(time.Duration(ttl) * time.Millisecond)
|
||||||
args[1],
|
db.Expire(key, expireTime)
|
||||||
}))
|
db.AddAof(reply.MakeMultiBulkReply([][]byte{
|
||||||
db.AddAof(makeExpireCmd(key, expireTime))
|
[]byte("SET"),
|
||||||
} else {
|
args[0],
|
||||||
db.Persist(key) // override ttl
|
args[1],
|
||||||
db.AddAof(makeAofCmd("set", args))
|
}))
|
||||||
}
|
db.AddAof(makeExpireCmd(key, expireTime))
|
||||||
|
} else if result > 0{
|
||||||
|
db.Persist(key) // override ttl
|
||||||
|
db.AddAof(makeAofCmd("set", args))
|
||||||
|
}else{
|
||||||
|
db.AddAof(makeAofCmd("set", args))
|
||||||
}
|
}
|
||||||
|
|
||||||
if policy == upsertPolicy || result > 0 {
|
if policy == upsertPolicy || result > 0 {
|
||||||
return &reply.OkReply{}
|
return &reply.OkReply{}
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user