|
|
|
@ -31,6 +31,7 @@ type DataBases struct {
|
|
|
|
|
mongoClient *mongo.Client
|
|
|
|
|
rdb go_redis.UniversalClient
|
|
|
|
|
Rc *rockscache.Client
|
|
|
|
|
WeakRc *rockscache.Client
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type RedisClient struct {
|
|
|
|
@ -145,13 +146,23 @@ func init() {
|
|
|
|
|
panic(err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 强一致性缓存,当一个key被标记删除,其他请求线程会被锁住轮询直到新的key生成,适合各种同步的拉取, 如果弱一致可能导致拉取还是老数据,毫无意义
|
|
|
|
|
DB.Rc = rockscache.NewClient(go_redis.NewClient(&go_redis.Options{
|
|
|
|
|
Addr: config.Config.Redis.DBAddress[0],
|
|
|
|
|
Password: config.Config.Redis.DBPassWord, // no password set
|
|
|
|
|
DB: 0, // use default DB
|
|
|
|
|
PoolSize: 100, // 连接池大小
|
|
|
|
|
}), rockscache.NewDefaultOptions())
|
|
|
|
|
DB.Rc.Options.StrongConsistency = true
|
|
|
|
|
|
|
|
|
|
// 弱一致性缓存,当一个key被标记删除,其他请求线程直接返回该key的value,适合高频并且生成很缓存很慢的情况 如大群发消息缓存的缓存
|
|
|
|
|
DB.WeakRc = rockscache.NewClient(go_redis.NewClient(&go_redis.Options{
|
|
|
|
|
Addr: config.Config.Redis.DBAddress[0],
|
|
|
|
|
Password: config.Config.Redis.DBPassWord, // no password set
|
|
|
|
|
DB: 0, // use default DB
|
|
|
|
|
PoolSize: 100, // 连接池大小
|
|
|
|
|
}), rockscache.NewDefaultOptions())
|
|
|
|
|
DB.WeakRc.Options.StrongConsistency = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func createMongoIndex(client *mongo.Client, collection string, isUnique bool, keys ...string) error {
|
|
|
|
|