Skip to content
This repository was archived by the owner on Sep 29, 2024. It is now read-only.

Commit 0349c35

Browse files
authoredFeb 8, 2023
Add DB option to RedisAdapterOptions (#564)
* Add option DB to RedisAdapterOptions
1 parent 1a06b55 commit 0349c35

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed
 

‎_examples/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ _, err := server.Adapter(&socketio.RedisAdapterOptions{
6464
Addr: "127.0.0.1:6379",
6565
Host: "127.0.0.1",
6666
Port: "6379",
67-
Prefix: "socket.io",
67+
Prefix: "socket.io",
68+
DB: 1,
6869
})
6970
if err != nil {
7071
log.Fatal("error:", err)

‎adapter_options.go

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type RedisAdapterOptions struct {
1212
Prefix string
1313
Network string
1414
Password string
15+
// DB : specifies the database to select when dialing a connection.
16+
DB int
1517
}
1618

1719
func (ro *RedisAdapterOptions) getAddr() string {

‎redis_broadcast.go

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func newRedisBroadcast(nsp string, opts *RedisAdapterOptions) (*redisBroadcast,
8484
if len(opts.Password) > 0 {
8585
redisOpts = append(redisOpts, redis.DialPassword(opts.Password))
8686
}
87+
if opts.DB > 0 {
88+
redisOpts = append(redisOpts, redis.DialDatabase(opts.DB))
89+
}
8790

8891
pub, err := redis.Dial(opts.Network, addr, redisOpts...)
8992
if err != nil {

‎server.go

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ func (s *Server) Adapter(opts *RedisAdapterOptions) (bool, error) {
3434
if len(opts.Password) > 0 {
3535
redisOpts = append(redisOpts, redis.DialPassword(opts.Password))
3636
}
37+
if opts.DB > 0 {
38+
redisOpts = append(redisOpts, redis.DialDatabase(opts.DB))
39+
}
3740

3841
conn, err := redis.Dial(opts.Network, opts.getAddr(), redisOpts...)
3942
if err != nil {

0 commit comments

Comments
 (0)
This repository has been archived.