2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 13:47:15 +08:00

feat: 添加redis驱动

This commit is contained in:
耗子
2024-11-09 02:41:47 +08:00
parent 8e74428023
commit 04d570197a
6 changed files with 172 additions and 1 deletions

34
pkg/db/redis.go Normal file
View File

@@ -0,0 +1,34 @@
package db
import (
"github.com/gomodule/redigo/redis"
)
type Redis struct {
conn redis.Conn
username string
password string
address string
}
func NewRedis(username, password, address string) (*Redis, error) {
conn, err := redis.Dial("tcp", address, redis.DialUsername(username), redis.DialPassword(password))
if err != nil {
return nil, err
}
return &Redis{
conn: conn,
username: username,
password: password,
address: address,
}, nil
}
func (r *Redis) Close() error {
return r.conn.Close()
}
func (r *Redis) Do(command string, args ...any) (any, error) {
return r.conn.Do(command, args...)
}