代码拉取完成,页面将自动刷新
package websocket
import (
"github.com/go-redis/redis"
"net/http"
"time"
)
type Option func(d *Hub)
type LoginFunc func(w http.ResponseWriter, r *http.Request) (int64, error)
type DispatchFunc func(uid int64, msg []byte)
type Logger interface {
Info(logs ...interface{})
Warn(logs ...interface{})
Debug(logs ...interface{})
Error(logs ...interface{})
}
type Redis interface {
ZAdd(key string, members ...redis.Z) *redis.IntCmd
Get(key string) *redis.StringCmd
Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd
ZRange(key string, start, stop int64) *redis.StringSliceCmd
ZRem(key string, members ...interface{}) *redis.IntCmd
ZCard(key string) *redis.IntCmd
ZRemRangeByRank(key string, start, stop int64) *redis.IntCmd
MGet(keys ...string) *redis.SliceCmd
Pipeline() redis.Pipeliner
}
func WithLogin(f LoginFunc) Option {
return func(d *Hub) {
d.login = f
}
}
func WithLogger(f Logger) Option {
return func(d *Hub) {
d.logger = f
}
}
func WithReceive(f DispatchFunc) Option {
return func(d *Hub) {
d.dispatch = f
}
}
func WithConcurrent(n int) Option {
return func(d *Hub) {
d.concurrent = make(chan struct{}, n)
}
}
// WithRedis maxCount 单个用户保存的最大消息数, maxTtl 缓存消息最长时间,单位秒
func WithRedis(maxCount, maxTtl int, redis Redis) Option {
return func(d *Hub) {
d.redis = NewRedisCache(maxCount, maxTtl, redis)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。