Redis.go 569 B

123456789101112131415161718192021222324252627282930313233
  1. package base
  2. import (
  3. "Server-Core/Server/Base/Log"
  4. "context"
  5. "github.com/go-redis/redis/v8"
  6. )
  7. type RdbInit struct {
  8. Addr string
  9. DB int
  10. Password string
  11. }
  12. type Rdb struct {
  13. client *redis.Client
  14. ctx context.Context
  15. }
  16. func (rdb *Rdb) Create(init *RdbInit) error {
  17. rdb.client = redis.NewClient(&redis.Options{
  18. Addr: init.Addr,
  19. Password: init.Password,
  20. DB: init.DB,
  21. })
  22. rdb.ctx = context.Background()
  23. _, err := rdb.client.Ping(rdb.ctx).Result()
  24. if err != nil {
  25. log.Error("Redis Create Error:%s", err.Error())
  26. }
  27. return err
  28. }