mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-13 04:23:54 +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:
|
||||
result = db.PutIfExists(key, entity)
|
||||
}
|
||||
if result > 0 {
|
||||
if ttl != unlimitedTTL {
|
||||
expireTime := time.Now().Add(time.Duration(ttl) * time.Millisecond)
|
||||
db.Expire(key, expireTime)
|
||||
db.AddAof(reply.MakeMultiBulkReply([][]byte{
|
||||
[]byte("SET"),
|
||||
args[0],
|
||||
args[1],
|
||||
}))
|
||||
db.AddAof(makeExpireCmd(key, expireTime))
|
||||
} else {
|
||||
db.Persist(key) // override ttl
|
||||
db.AddAof(makeAofCmd("set", args))
|
||||
}
|
||||
/*
|
||||
* 如果设置了ttl 则以最新的ttl为准
|
||||
* 如果没有设置ttl 是新增key的情况,不设置ttl。
|
||||
* 如果没有设置ttl 且已存在key的 不修改ttl 但需要增加aof
|
||||
*/
|
||||
if ttl != unlimitedTTL {
|
||||
expireTime := time.Now().Add(time.Duration(ttl) * time.Millisecond)
|
||||
db.Expire(key, expireTime)
|
||||
db.AddAof(reply.MakeMultiBulkReply([][]byte{
|
||||
[]byte("SET"),
|
||||
args[0],
|
||||
args[1],
|
||||
}))
|
||||
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 {
|
||||
return &reply.OkReply{}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user