drone/dbop/redisop.go
liupeng fde11d3ff9
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
update
2024-02-28 15:41:40 +08:00

40 lines
700 B
Go

package dbop
import (
"fmt"
"time"
"github.com/go-redis/redis"
)
const (
RD_TRADE_HEAD = "MTPAY:"
)
var (
RDb *redis.Client
)
// 初始化连接
func RedisInit(host, port, passwd string) {
RDb = redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%s", host, port),
Password: passwd, // no password set
DB: 0, // use default DB
PoolSize: 20, // 连接池大小
})
_, err := RDb.Ping().Result()
if err != nil {
panic("Redis初始化失败")
}
}
func CheckRedisTrade(tradeNo string) bool {
_, err := RDb.Get(RD_TRADE_HEAD + tradeNo).Result()
if err == redis.Nil {
RDb.Set(RD_TRADE_HEAD+tradeNo, "true", 30*time.Minute)
return false
}
return true
}