mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-10 07:42:26 +08:00
14
cache/redis.go
vendored
14
cache/redis.go
vendored
@@ -14,12 +14,12 @@ type Redis struct {
|
|||||||
|
|
||||||
//RedisOpts redis 连接属性
|
//RedisOpts redis 连接属性
|
||||||
type RedisOpts struct {
|
type RedisOpts struct {
|
||||||
Host string
|
Host string `yml:"host" json:"host"`
|
||||||
Password string
|
Password string `yml:"password" json:"password"`
|
||||||
Database int
|
Database int `yml:"database" json:"database"`
|
||||||
MaxIdle int
|
MaxIdle int `yml:"max_idle" json:"max_idle"`
|
||||||
MaxActive int
|
MaxActive int `yml:"max_active" json:"max_active"`
|
||||||
IdleTimeout time.Duration //second
|
IdleTimeout int32 `yml:"idle_timeout" json:"idle_timeout"` //second
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewRedis 实例化
|
//NewRedis 实例化
|
||||||
@@ -27,7 +27,7 @@ func NewRedis(opts *RedisOpts) *Redis {
|
|||||||
pool := &redis.Pool{
|
pool := &redis.Pool{
|
||||||
MaxActive: opts.MaxActive,
|
MaxActive: opts.MaxActive,
|
||||||
MaxIdle: opts.MaxIdle,
|
MaxIdle: opts.MaxIdle,
|
||||||
IdleTimeout: opts.IdleTimeout,
|
IdleTimeout: time.Second * time.Duration(opts.IdleTimeout),
|
||||||
Dial: func() (redis.Conn, error) {
|
Dial: func() (redis.Conn, error) {
|
||||||
return redis.Dial("tcp", opts.Host,
|
return redis.Dial("tcp", opts.Host,
|
||||||
redis.DialDatabase(opts.Database),
|
redis.DialDatabase(opts.Database),
|
||||||
|
|||||||
6
js/js.go
6
js/js.go
@@ -44,7 +44,7 @@ func NewJs(context *context.Context) *Js {
|
|||||||
func (js *Js) GetConfig(uri string) (config *Config, err error) {
|
func (js *Js) GetConfig(uri string) (config *Config, err error) {
|
||||||
config = new(Config)
|
config = new(Config)
|
||||||
var ticketStr string
|
var ticketStr string
|
||||||
ticketStr, err = js.getTicket()
|
ticketStr, err = js.GetTicket()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -61,8 +61,8 @@ func (js *Js) GetConfig(uri string) (config *Config, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//getTicket 获取jsapi_tocket全局缓存
|
//GetTicket 获取jsapi_tocket
|
||||||
func (js *Js) getTicket() (ticketStr string, err error) {
|
func (js *Js) GetTicket() (ticketStr string, err error) {
|
||||||
js.GetJsAPITicketLock().Lock()
|
js.GetJsAPITicketLock().Lock()
|
||||||
defer js.GetJsAPITicketLock().Unlock()
|
defer js.GetJsAPITicketLock().Unlock()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user