From f9eb83238b99a142d9492c41aadd238aea4b0b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=81=E6=A0=91=E7=AB=8B?= <1923244321@qq.com> Date: Tue, 26 Jan 2021 21:00:01 +0800 Subject: [PATCH 1/2] Update string.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit set 时 如果设置了ttl 则以最新的ttl为准 如果没有设置ttl 且数据新增数据的,不设置过期时间。 --- src/db/string.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/db/string.go b/src/db/string.go index abf985b..70aefb3 100644 --- a/src/db/string.go +++ b/src/db/string.go @@ -121,21 +121,24 @@ 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 且数据新增数据的,不设置过期时间。 + */ + 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)) } + if policy == upsertPolicy || result > 0 { return &reply.OkReply{} } else { From df4f96b4c39d15595f8a3e3e53d41f2c635080da Mon Sep 17 00:00:00 2001 From: neo <1923244321@qq.com> Date: Wed, 27 Jan 2021 15:30:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?/*=20=20=20=20=20=20*=20=20=20=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E8=AE=BE=E7=BD=AE=E4=BA=86ttl=20=E5=88=99=E4=BB=A5?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=9A=84ttl=E4=B8=BA=E5=87=86=20=20=20=20=20?= =?UTF-8?q?=20*=20=20=20=E5=A6=82=E6=9E=9C=E6=B2=A1=E6=9C=89=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEttl=20=E6=98=AF=E6=96=B0=E5=A2=9Ekey=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=EF=BC=8C=E4=B8=8D=E8=AE=BE=E7=BD=AEttl=E3=80=82=20=20?= =?UTF-8?q?=20=20=20=20*=20=20=20=E5=A6=82=E6=9E=9C=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=AE=BE=E7=BD=AEttl=20=E4=B8=94=E5=B7=B2=E5=AD=98=E5=9C=A8key?= =?UTF-8?q?=E7=9A=84=20=E4=B8=8D=E4=BF=AE=E6=94=B9ttl=20=E4=BD=86=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E5=A2=9E=E5=8A=A0aof=20=20=20=20=20*/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/string.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/db/string.go b/src/db/string.go index 70aefb3..28a5727 100644 --- a/src/db/string.go +++ b/src/db/string.go @@ -123,7 +123,8 @@ func Set(db *DB, args [][]byte) redis.Reply { } /* * 如果设置了ttl 则以最新的ttl为准 - * 如果没有设置ttl 且数据新增数据的,不设置过期时间。 + * 如果没有设置ttl 是新增key的情况,不设置ttl。 + * 如果没有设置ttl 且已存在key的 不修改ttl 但需要增加aof */ if ttl != unlimitedTTL { expireTime := time.Now().Add(time.Duration(ttl) * time.Millisecond) @@ -137,6 +138,8 @@ func Set(db *DB, args [][]byte) redis.Reply { } 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 {