Skip to content

Commit

Permalink
Merge branch 'HDT3213:master' into feat/scanCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
NaNShaner authored Oct 17, 2023
2 parents 24e3509 + 04d118c commit 7ada186
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
8 changes: 3 additions & 5 deletions database/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ func TestExpireAt(t *testing.T) {
}

func TestExpiredTime(t *testing.T) {
//测试ExpireTime
testDB.Flush()
key := utils.RandString(10)
value := utils.RandString(10)
Expand All @@ -204,6 +203,7 @@ func TestExpiredTime(t *testing.T) {
result = testDB.Exec(nil, utils.ToCmdLine("PEXPIRETIME", key))
asserts.AssertIntReply(t, result, -1)

estimateExpireTimestamp := time.Now().Add(2 * time.Second).Unix() // actually expiration may be >= estimateExpireTimestamp
testDB.Exec(nil, utils.ToCmdLine("EXPIRE", key, "2"))
//tt := time.Now()
result = testDB.Exec(nil, utils.ToCmdLine("ttl", key))
Expand All @@ -217,25 +217,23 @@ func TestExpiredTime(t *testing.T) {
return
}
result = testDB.Exec(nil, utils.ToCmdLine("EXPIRETIME", key))
asserts.AssertIntReply(t, result, int(time.Now().Add(2*time.Second).Unix()))
intResult, ok = result.(*protocol.IntReply)
if !ok {
t.Errorf("expected int protocol, actually %s", result.ToBytes())
return
}
if intResult.Code <= 0 {
if intResult.Code < estimateExpireTimestamp {
t.Errorf("expected ttl more than 0, actual: %d", intResult.Code)
return
}

result = testDB.Exec(nil, utils.ToCmdLine("PEXPIRETIME", key))
asserts.AssertIntReply(t, result, int(time.Now().Add(2*time.Second).UnixMilli()))
intResult, ok = result.(*protocol.IntReply)
if !ok {
t.Errorf("expected int protocol, actually %s", result.ToBytes())
return
}
if intResult.Code <= 0 {
if intResult.Code < estimateExpireTimestamp*1000 {
t.Errorf("expected ttl more than 0, actual: %d", intResult.Code)
return
}
Expand Down
1 change: 0 additions & 1 deletion database/sortedset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ func TestZRangeByScore(t *testing.T) {
asserts.AssertMultiBulkReply(t, result, members[20:31])
result = testDB.Exec(nil, utils.ToCmdLine("ZRangeByScore", key, min, max, "WithScores"))
asserts.AssertMultiBulkReplySize(t, result, 22)
result = execZRevRangeByScore(testDB, utils.ToCmdLine(key, max, min))
result = testDB.Exec(nil, utils.ToCmdLine("ZRevRangeByScore", key, max, min))
asserts.AssertMultiBulkReply(t, result, reverse(members[20:31]))

Expand Down
15 changes: 11 additions & 4 deletions datastruct/list/quicklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,17 @@ func (iter *iterator) remove() interface{} {
} else {
// page is empty, update iter.node and iter.offset
if iter.node == iter.ql.data.Back() {
// removed last element, ql is empty now
iter.ql.data.Remove(iter.node)
iter.node = nil
iter.offset = 0
// move iter so iter.atEnd() can be true
if prevNode := iter.node.Prev(); prevNode != nil {
iter.ql.data.Remove(iter.node)
iter.node = prevNode
iter.offset = len(prevNode.Value.([]interface{}))
} else {
// removed last element, ql is empty now
iter.ql.data.Remove(iter.node)
iter.node = nil
iter.offset = 0
}
} else {
nextNode := iter.node.Next()
iter.ql.data.Remove(iter.node)
Expand Down
6 changes: 6 additions & 0 deletions tcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func ListenAndServe(listener net.Listener, handler tcp.Handler, closeChan <-chan
for {
conn, err := listener.Accept()
if err != nil {
// learn from net/http/serve.go#Serve()
if ne, ok := err.(net.Error); ok && ne.Timeout() {
logger.Infof("accept occurs temporary error: %v, retry in 5ms", err)
time.Sleep(5 * time.Millisecond)
continue
}
errCh <- err
break
}
Expand Down

0 comments on commit 7ada186

Please sign in to comment.