Skip to content

Commit ace1fd0

Browse files
authored
chore: switch old store to snowdreamtech/redistore (#269)
- Remove `github.com/boj/redistore` dependency from `go.mod` - Update `github.com/gomodule/redigo` to version `v1.9.2` in `go.mod` - Add `github.com/snowdreamtech/redistore` dependency to `go.mod` - Replace `github.com/boj/redistore` import with `github.com/snowdreamtech/redistore` in `redis.go` - Add detailed comments for `NewStoreWithDB` function parameters and return values - Add detailed comments for `NewStoreWithPool` function parameters and return values - Add detailed comments for `GetRedisStore` function parameters and return values - Add detailed comments for `SetKeyPrefix` function parameters and return values cc @snowdream Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent 8e4ea71 commit ace1fd0

3 files changed

Lines changed: 50 additions & 17 deletions

File tree

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ go 1.19
44

55
require (
66
github.com/antonlindstrom/pgstore v0.0.0-20220421113606-e3a6e3fed12a
7-
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff
87
github.com/bos-hieu/mongostore v0.0.3
98
github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874
109
github.com/bradleypeabody/gorilla-sessions-memcache v0.0.0-20181103040241-659414f458e1
1110
github.com/gin-gonic/gin v1.9.1
1211
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
13-
github.com/gomodule/redigo v2.0.0+incompatible
12+
github.com/gomodule/redigo v1.9.2
1413
github.com/gorilla/context v1.1.2
1514
github.com/gorilla/sessions v1.2.2
1615
github.com/kidstuff/mongostore v0.0.0-20181113001930-e650cd85ee4b
1716
github.com/memcachier/mc v2.0.1+incompatible
1817
github.com/quasoft/memstore v0.0.0-20191010062613-2bce066d2b0b
18+
github.com/snowdreamtech/redistore v0.0.0-20231007100540-6364ca2c97b4
1919
github.com/wader/gormstore/v2 v2.0.3
2020
go.mongodb.org/mongo-driver v1.14.0
2121
gorm.io/driver/sqlite v1.4.4

go.sum

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
22
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
33
github.com/antonlindstrom/pgstore v0.0.0-20220421113606-e3a6e3fed12a h1:dIdcLbck6W67B5JFMewU5Dba1yKZA3MsT67i4No/zh0=
44
github.com/antonlindstrom/pgstore v0.0.0-20220421113606-e3a6e3fed12a/go.mod h1:Sdr/tmSOLEnncCuXS5TwZRxuk7deH1WXVY8cve3eVBM=
5-
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff h1:RmdPFa+slIr4SCBg4st/l/vZWVe9QJKMXGO60Bxbe04=
6-
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw=
75
github.com/bos-hieu/mongostore v0.0.3 h1:wla8pz4VQU8JOcbo+sBbuvFVBBHt3yRelVSi6YInC48=
86
github.com/bos-hieu/mongostore v0.0.3/go.mod h1:8AbbVmDEb0yqJsBrWxZIAZOxIfv/tsP8CDtdHduZHGg=
97
github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874 h1:N7oVaKyGp8bttX0bfZGmcGkjz7DLQXhAn3DNd3T0ous=
@@ -53,19 +51,17 @@ github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MG
5351
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
5452
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
5553
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
56-
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
57-
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
54+
github.com/gomodule/redigo v1.9.2 h1:HrutZBLhSIU8abiSfW8pj8mPhOyMYjZT/wcA4/L9L9s=
55+
github.com/gomodule/redigo v1.9.2/go.mod h1:KsU3hiK/Ay8U42qpaJk+kuNa3C+spxapWpM+ywhcgtw=
5856
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
5957
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
6058
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
6159
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
62-
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
6360
github.com/gorilla/context v1.1.2 h1:WRkNAv2uoa03QNIc1A6u4O7DAGMUVoopZhkiXWA2V1o=
6461
github.com/gorilla/context v1.1.2/go.mod h1:KDPwT9i/MeWHiLl90fuTgrt4/wPcv75vFAZLaOOcbxM=
6562
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
6663
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
6764
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
68-
github.com/gorilla/sessions v1.1.1/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w=
6965
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
7066
github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY=
7167
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
@@ -185,6 +181,8 @@ github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9Nz
185181
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
186182
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
187183
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
184+
github.com/snowdreamtech/redistore v0.0.0-20231007100540-6364ca2c97b4 h1:HniAbmj6IsZzZuAouulfsyTDjODtBymeWqbh5lK3EmY=
185+
github.com/snowdreamtech/redistore v0.0.0-20231007100540-6364ca2c97b4/go.mod h1:VTV42RFvMAoztNB+4GFSAbINm6ZioJjYQvdT/RrIGIM=
188186
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
189187
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
190188
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=

redis/redis.go

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package redis
33
import (
44
"errors"
55

6-
"github.com/boj/redistore"
76
"github.com/gin-contrib/sessions"
7+
88
"github.com/gomodule/redigo/redis"
9+
"github.com/snowdreamtech/redistore"
910
)
1011

1112
type Store interface {
@@ -33,10 +34,19 @@ func NewStore(size int, network, address, password string, keyPairs ...[]byte) (
3334
return &store{s}, nil
3435
}
3536

36-
// NewStoreWithDB - like NewStore but accepts `DB` parameter to select
37-
// redis DB instead of using the default one ("0")
37+
// NewStoreWithDB creates a new Redis-based session store with the specified parameters.
38+
//
39+
// Parameters:
40+
// - size: The maximum number of idle connections in the pool.
41+
// - network: The network type (e.g., "tcp").
42+
// - address: The address of the Redis server (e.g., "localhost:6379").
43+
// - password: The password for the Redis server (if any).
44+
// - DB: The Redis database to be selected after connecting.
45+
// - keyPairs: A variadic list of byte slices used for authentication and encryption.
3846
//
39-
// Ref: https://godoc.org/github.com/boj/redistore#NewRediStoreWithDB
47+
// Returns:
48+
// - Store: The created session store.
49+
// - error: An error if the store could not be created.
4050
func NewStoreWithDB(size int, network, address, password, DB string, keyPairs ...[]byte) (Store, error) {
4151
s, err := redistore.NewRediStoreWithDB(size, network, address, password, DB, keyPairs...)
4252
if err != nil {
@@ -45,9 +55,18 @@ func NewStoreWithDB(size int, network, address, password, DB string, keyPairs ..
4555
return &store{s}, nil
4656
}
4757

48-
// NewStoreWithPool instantiates a RediStore with a *redis.Pool passed in.
58+
// NewStoreWithPool creates a new session store using a Redis connection pool.
59+
// It takes a redis.Pool and an optional variadic list of key pairs for
60+
// authentication and encryption of session data.
4961
//
50-
// Ref: https://godoc.org/github.com/boj/redistore#NewRediStoreWithPool
62+
// Parameters:
63+
// - pool: A redis.Pool object that manages a pool of Redis connections.
64+
// - keyPairs: Optional variadic list of byte slices used for authentication
65+
// and encryption of session data.
66+
//
67+
// Returns:
68+
// - Store: A new session store backed by Redis.
69+
// - error: An error if the store could not be created.
5170
func NewStoreWithPool(pool *redis.Pool, keyPairs ...[]byte) (Store, error) {
5271
s, err := redistore.NewRediStoreWithPool(pool, keyPairs...)
5372
if err != nil {
@@ -60,8 +79,15 @@ type store struct {
6079
*redistore.RediStore
6180
}
6281

63-
// GetRedisStore get the actual woking store.
64-
// Ref: https://godoc.org/github.com/boj/redistore#RediStore
82+
// GetRedisStore retrieves the Redis store from the provided Store interface.
83+
// It returns an error if the provided Store is not of the expected type.
84+
//
85+
// Parameters:
86+
// - s: The Store interface from which to retrieve the Redis store.
87+
//
88+
// Returns:
89+
// - err: An error if the provided Store is not of the expected type.
90+
// - rediStore: The retrieved Redis store, or nil if there was an error.
6591
func GetRedisStore(s Store) (err error, rediStore *redistore.RediStore) {
6692
realStore, ok := s.(*store)
6793
if !ok {
@@ -73,7 +99,16 @@ func GetRedisStore(s Store) (err error, rediStore *redistore.RediStore) {
7399
return
74100
}
75101

76-
// SetKeyPrefix sets the key prefix in the redis database.
102+
// SetKeyPrefix sets a key prefix for the given Redis store.
103+
// It retrieves the Redis store from the provided Store interface and sets the key prefix.
104+
// If there is an error retrieving the Redis store, it returns the error.
105+
//
106+
// Parameters:
107+
// - s: The Store interface from which the Redis store will be retrieved.
108+
// - prefix: The key prefix to be set for the Redis store.
109+
//
110+
// Returns:
111+
// - error: An error if there is an issue retrieving the Redis store, otherwise nil.
77112
func SetKeyPrefix(s Store, prefix string) error {
78113
err, rediStore := GetRedisStore(s)
79114
if err != nil {

0 commit comments

Comments
 (0)