Skip to content

Commit

Permalink
Merge pull request #10 from gmhafiz/master
Browse files Browse the repository at this point in the history
add Close()
  • Loading branch information
rbcervilla authored Aug 2, 2021
2 parents 56a7d2a + 89c87e8 commit 541a107
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions redisstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func (s *RedisStore) Serializer(ss SessionSerializer) {
s.serializer = ss
}

func (s *RedisStore) Close() error {
return s.client.Close()
}

// save writes session in Redis
func (s *RedisStore) save(ctx context.Context, session *sessions.Session) error {

Expand Down
27 changes: 27 additions & 0 deletions redisstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,30 @@ func TestDelete(t *testing.T) {
t.Fatal("failed to delete session: ", err)
}
}

func TestClose(t *testing.T) {
client := redis.NewClient(&redis.Options{
Addr: redisAddr,
})

cmd := client.Ping(context.Background())
err := cmd.Err()
if err != nil {
t.Fatal("connection is not opened")
}

store, err := NewRedisStore(context.Background(), client)
if err != nil {
t.Fatal("failed to create redis store", err)
}

err = store.Close()
if err != nil {
t.Fatal("failed to close")
}

cmd = client.Ping(context.Background())
if cmd.Err() == nil {
t.Fatal("connection is properly closed")
}
}

0 comments on commit 541a107

Please sign in to comment.