Skip to content

Commit 6beca73

Browse files
committed
feat: add util redis
1 parent fa1114e commit 6beca73

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

util/redis.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package util
2+
3+
import "github.com/go-redis/redis"
4+
5+
var rdb *redis.Client
6+
7+
// OpenRedis create a connection of redis
8+
func OpenRedis() error {
9+
rdb = redis.NewClient(&redis.Options{
10+
Addr: "localhost:6379",
11+
Password: "", // no password set
12+
DB: 0, // use default DB
13+
})
14+
15+
_, err := rdb.Ping().Result()
16+
if err != nil {
17+
return err
18+
}
19+
return nil
20+
}
21+
22+
// GetRedis return the pointer of db
23+
func GetRedis() *redis.Client {
24+
return rdb
25+
}

0 commit comments

Comments
 (0)