You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
576 B

  1. package initRedis
  2. import (
  3. "fmt"
  4. "gin-vue-admin/config"
  5. "github.com/go-redis/redis"
  6. )
  7. var DEFAULTREDIS *redis.Client
  8. func InitRedis() (client *redis.Client) {
  9. client = redis.NewClient(&redis.Options{
  10. Addr: config.GinVueAdminconfig.RedisAdmin.Addr,
  11. Password: config.GinVueAdminconfig.RedisAdmin.Password, // no password set
  12. DB: config.GinVueAdminconfig.RedisAdmin.DB, // use default DB
  13. })
  14. pong, err := client.Ping().Result()
  15. if err != nil {
  16. fmt.Println(pong, err)
  17. } else {
  18. fmt.Println(pong, err)
  19. DEFAULTREDIS = client
  20. }
  21. return client
  22. }