mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-05 05:12:45 +08:00
* pb * fix: Modifying other fields while setting IsPrivateChat does not take effect * fix: quote message error revoke * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * upgrading pkg tools * fix * fix * optimize log output * feat: support GetLastMessage * feat: support GetLastMessage * feat: s3 switch * feat: s3 switch * fix: GetUsersOnline * feat: SendBusinessNotification supported configuration parameters * feat: SendBusinessNotification supported configuration parameters * feat: SendBusinessNotification supported configuration parameters * feat: seq conversion failed without exiting * monolithic * fix: DeleteDoc crash * fix: DeleteDoc crash * fix: monolithic * fix: monolithic * fix: fill send time * fix: fill send time * fix: crash caused by withdrawing messages from users who have left the group * fix: mq * fix: mq * fix: user msg timestamp * fix: mq * 1 * 1 * 1 * 1 * 1 * 1 * 1 * seq read config * seq read config * 1 * 1 * fix: the source message of the reference is withdrawn, and the referenced message is deleted * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1
77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
package dbbuild
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
"github.com/openimsdk/tools/db/mongoutil"
|
|
"github.com/openimsdk/tools/db/redisutil"
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
const (
|
|
standaloneMongo = "mongo"
|
|
standaloneRedis = "redis"
|
|
)
|
|
|
|
var globalStandalone = &standalone{}
|
|
|
|
type standaloneConn[C any] struct {
|
|
Conn C
|
|
Err error
|
|
}
|
|
|
|
func (x *standaloneConn[C]) result() (C, error) {
|
|
return x.Conn, x.Err
|
|
}
|
|
|
|
type standalone struct {
|
|
lock sync.Mutex
|
|
mongo *config.Mongo
|
|
redis *config.Redis
|
|
conn map[string]any
|
|
}
|
|
|
|
func (x *standalone) setConfig(mongoConf *config.Mongo, redisConf *config.Redis) {
|
|
x.lock.Lock()
|
|
defer x.lock.Unlock()
|
|
x.mongo = mongoConf
|
|
x.redis = redisConf
|
|
}
|
|
|
|
func (x *standalone) Mongo(ctx context.Context) (*mongoutil.Client, error) {
|
|
x.lock.Lock()
|
|
defer x.lock.Unlock()
|
|
if x.conn == nil {
|
|
x.conn = make(map[string]any)
|
|
}
|
|
v, ok := x.conn[standaloneMongo]
|
|
if !ok {
|
|
var val standaloneConn[*mongoutil.Client]
|
|
val.Conn, val.Err = mongoutil.NewMongoDB(ctx, x.mongo.Build())
|
|
v = &val
|
|
x.conn[standaloneMongo] = v
|
|
}
|
|
return v.(*standaloneConn[*mongoutil.Client]).result()
|
|
}
|
|
|
|
func (x *standalone) Redis(ctx context.Context) (redis.UniversalClient, error) {
|
|
x.lock.Lock()
|
|
defer x.lock.Unlock()
|
|
if x.redis.Disable {
|
|
return nil, nil
|
|
}
|
|
if x.conn == nil {
|
|
x.conn = make(map[string]any)
|
|
}
|
|
v, ok := x.conn[standaloneRedis]
|
|
if !ok {
|
|
var val standaloneConn[redis.UniversalClient]
|
|
val.Conn, val.Err = redisutil.NewRedisClient(ctx, x.redis.Build())
|
|
v = &val
|
|
x.conn[standaloneRedis] = v
|
|
}
|
|
return v.(*standaloneConn[redis.UniversalClient]).result()
|
|
}
|