Skip to content

Commit

Permalink
Update to RefreshTTL
Browse files Browse the repository at this point in the history
  • Loading branch information
mjc-gh committed Jun 23, 2024
1 parent 03ac792 commit 1ffb09e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ go 1.19

require (
github.com/fatih/color v1.16.0
github.com/mjc-gh/redis-test-hook v0.1.0
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5
github.com/redis/go-redis/v9 v9.0.5
github.com/stretchr/testify v1.8.2
github.com/redis/go-redis/v9 v9.5.1
github.com/stretchr/testify v1.9.0
)

require (
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mjc-gh/redis-test-hook v0.1.0 h1:JpYPKhtNF8EdKm4FBOa0tJ3er1yaJUlnXZ7RSNihcm0=
github.com/mjc-gh/redis-test-hook v0.1.0/go.mod h1:w2hc7+/d23bEVg3BV1iQOIUn+wBWfqTVDfpFMs4ubkY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5 h1:EaDatTxkdHG+U3Bk4EUr+DZ7fOGwTfezUiUJMaIcaho=
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5/go.mod h1:fyalQWdtzDBECAQFBJuQe5bzQ02jGd5Qcbgb97Flm7U=
github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o=
github.com/redis/go-redis/v9 v9.0.5/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8=
github.com/redis/go-redis/v9 v9.5.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
Expand Down
11 changes: 11 additions & 0 deletions kredis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"fmt"
"testing"

redistesthooks "github.com/mjc-gh/redis-test-hook"
"github.com/stretchr/testify/suite"
)

type KredisTestSuite struct {
suite.Suite
captureHook *redistesthooks.Hook
}

type testLogger struct{ stdLogger }
Expand All @@ -24,10 +26,16 @@ func (suite *KredisTestSuite) SetupTest() {
// TODO use a unique namespace for each test (thus potentially enabling
// parallel tests)
SetConfiguration("shared", "ns", "redis://localhost:6379/2")
SetConfiguration("capture", "ns", "redis://localhost:6379/2")
SetConfiguration("badconn", "", "redis://localhost:1234/0")

EnableDebugLogging()

suite.captureHook = redistesthooks.New()

client, _, _ := getConnection("capture")
client.AddHook(suite.captureHook)

testWarnings = []string{}
SetDebugLogger(&testLogger{})
}
Expand All @@ -43,9 +51,12 @@ func (suite *KredisTestSuite) TearDownTest() {
c.Del(ctx, key)
}

suite.captureHook.Reset()

// Reset connections
delete(connections, "shared")
delete(connections, "badconn")
delete(connections, "capture")
}

// listen for 'go test' command --> run test methods
Expand Down
2 changes: 1 addition & 1 deletion proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ func (p *Proxy) RefreshTTL() (bool, error) {
return false, nil
}

return p.client.ExpireXX(p.ctx, p.key, p.expiresIn).Result()
return p.client.Expire(p.ctx, p.key, p.expiresIn).Result()
}
10 changes: 2 additions & 8 deletions slot_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package kredis

import "time"

func (s *KredisTestSuite) TestSlot() {
slot, err := NewSlot("slot", 3)
s.NoError(err)
Expand All @@ -25,17 +23,13 @@ func (s *KredisTestSuite) TestSlot() {
}

func (s KredisTestSuite) TestSlotExpiry() {
slot, err := NewSlot("slot", 1, WithExpiry("1ms"))
slot, err := NewSlot("slot", 1, WithConfigName("capture"), WithExpiry("5s"))
s.NoError(err)

slot.Reserve()
s.False(slot.IsAvailable())

time.Sleep(2 * time.Millisecond)

dur, err := slot.TTL()
s.NoError(err)
s.Equal(time.Duration(-1), dur)
s.Equal("EXPIRE ns:slot 5", s.captureHook.Captures[2].String())
}

func (s *KredisTestSuite) TestSlotWithReserveCallback() {
Expand Down

0 comments on commit 1ffb09e

Please sign in to comment.