40 lines
700 B
Go
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
|
|
}
|