加入网络层

This commit is contained in:
2025-06-26 23:57:54 +08:00
parent 53106465ed
commit 0f29dccec4
57 changed files with 1859 additions and 1274 deletions

View File

@@ -0,0 +1,34 @@
package redis
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
var (
cli *redis.Client
Nil = redis.Nil
)
func Init(host string, port int, password string, db int) error {
cli = redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%d", host, port),
Password: password,
DB: db,
})
_, err := cli.Ping(context.Background()).Result()
return err
}
func Client() *redis.Client {
return cli
}
func Close() error {
if cli != nil {
return cli.Close()
}
return nil
}