-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbhandler.go
42 lines (32 loc) · 851 Bytes
/
dbhandler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/mediocregopher/radix.v2/pool"
)
type DBConnection struct {
db *sql.DB
cache *pool.Pool
}
func OpenConnectionSession() (dbConnection *DBConnection) {
dbConnection = new(DBConnection)
dbConnection.createNewDBConnection()
dbConnection.createNewCacheConnection()
return
}
func (dbConnection *DBConnection) createNewDBConnection() (err error) {
connection, err := sql.Open("mysql", "root@/social_store?charset=utf8")
if err != nil {
panic(err)
}
fmt.Println("MySQL Connection is Active")
dbConnection.db = connection
return
}
func (dbConnection *DBConnection) createNewCacheConnection() (err error) {
cache, err := pool.New("tcp", "127.0.0.1:6379", 10)
fmt.Println("Redis Connection is Active")
dbConnection.cache = cache
return
}