Documentation ¶
Index ¶
- Variables
- func GetRedisCachePrefix() string
- func InitMongoMasterConn(config MongoConfig, logger echo.Logger) (*mongo.Client, string)
- func InitMongoTenantConns(config MongoConfig, master *gorm.DB, ...) (map[uint64]*mongo.Client, map[uint64]string)
- func InitMysqlMasterConn(config SQLConfig) (*gorm.DB, string)
- func InitMysqlTenantConns(config SQLConfig, master *gorm.DB, ...) (map[uint64]*gorm.DB, map[uint64]string)
- func InitRedisTenantConns(config RedisConfig, masterMySQL *gorm.DB, ...) map[uint64]*RedisDBConn
- type FieldValuePair
- type KeyFieldPair
- type MemoryConfig
- type MongoConfig
- type RedisConfig
- type RedisDBConn
- func (clients *RedisDBConn) DelKey(c context.Context, keys ...string) error
- func (clients *RedisDBConn) Eval(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)
- func (clients *RedisDBConn) EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) (interface{}, error)
- func (clients *RedisDBConn) ExpireKey(c context.Context, key string, ttl time.Duration) error
- func (clients *RedisDBConn) GetLRange(c context.Context, key string, start, stop int64) (str []string, err error)
- func (clients *RedisDBConn) GetString(c context.Context, key string) (str string, err error)
- func (clients *RedisDBConn) HGet(c context.Context, key string, field string) (result string, err error)
- func (clients *RedisDBConn) HGetAll(c context.Context, key string) (result map[string]string, err error)
- func (clients *RedisDBConn) HGets(c context.Context, redisKeysWithField map[string]string) (map[string]string, error)
- func (clients *RedisDBConn) HMGet(c context.Context, key string, fields ...string) (result []interface{}, err error)
- func (clients *RedisDBConn) HSet(c context.Context, key string, args ...interface{}) error
- func (clients *RedisDBConn) IncrementValue(c context.Context, key string) error
- func (clients *RedisDBConn) KeyExists(c context.Context, key string) (bool, error)
- func (clients *RedisDBConn) Keys(c context.Context, pattern string) (keys []string, err error)
- func (clients *RedisDBConn) MGet(c context.Context, keys ...string) (result []interface{}, err error)
- func (clients *RedisDBConn) MSet(c context.Context, values ...interface{}) (err error)
- func (clients *RedisDBConn) MSetWithTTL(c context.Context, ttl time.Duration, values ...interface{}) (err error)
- func (clients *RedisDBConn) Pipeline() redis.Pipeliner
- func (clients *RedisDBConn) Pipelined(c context.Context, fn func(redis.Pipeliner) error) ([]redis.Cmder, error)
- func (clients *RedisDBConn) RPush(c context.Context, key string, valueList []string) error
- func (clients *RedisDBConn) Run(ctx context.Context, script *redis.Script, keys []string, args ...interface{}) (interface{}, error)
- func (clients *RedisDBConn) SAdd(c context.Context, key string, elements interface{}) error
- func (clients *RedisDBConn) SIsMember(c context.Context, key string, element interface{}) (found bool, err error)
- func (clients *RedisDBConn) SMembers(c context.Context, key string) (str []string, err error)
- func (clients *RedisDBConn) SRandMemberN(c context.Context, key string, count int64) (result []string, err error)
- func (clients *RedisDBConn) SRem(c context.Context, key string, elements interface{}) error
- func (clients *RedisDBConn) Set(c context.Context, key string, data interface{}, ttl time.Duration) error
- func (clients *RedisDBConn) SetJSON(c context.Context, key string, data interface{}, ttl time.Duration) error
- func (clients *RedisDBConn) TTL(c context.Context, key string) (ttl time.Duration, err error)
- type SQLConfig
- type TenantConnections
Constants ¶
This section is empty.
Variables ¶
var ErrRedisInvalidParameter = errors.New("redis invalid parameter")
Functions ¶
func GetRedisCachePrefix ¶
func GetRedisCachePrefix() string
func InitMongoMasterConn ¶
func InitMongoMasterConn(config MongoConfig, logger echo.Logger) (*mongo.Client, string)
func InitMongoTenantConns ¶
func InitMongoTenantConns(config MongoConfig, master *gorm.DB, tenantAlterDbHostParam, tenantDBPassPhraseKey string, logger echo.Logger) (map[uint64]*mongo.Client, map[uint64]string)
Init the mongo database connection map.
func InitMysqlMasterConn ¶
InitMysqlMasterConn returns mysql master db connection.
func InitMysqlTenantConns ¶
func InitRedisTenantConns ¶
func InitRedisTenantConns(config RedisConfig, masterMySQL *gorm.DB, tenantAlterDbHostParam, tenantDBPassPhraseKey string) map[uint64]*RedisDBConn
Types ¶
type FieldValuePair ¶
type KeyFieldPair ¶
type MemoryConfig ¶
type MongoConfig ¶
type RedisConfig ¶
type RedisDBConn ¶
type RedisDBConn struct { Primary redis.UniversalClient Reads map[uint64]redis.UniversalClient Name int // contains filtered or unexported fields }
RedisDBConn IMPORTANT: This structure is holding any kind of redis connection using a map in bean.go.
func InitRedisMasterConn ¶
func InitRedisMasterConn(config RedisConfig) *RedisDBConn
func (*RedisDBConn) DelKey ¶
func (clients *RedisDBConn) DelKey(c context.Context, keys ...string) error
func (*RedisDBConn) Eval ¶ added in v2.3.0
func (clients *RedisDBConn) Eval(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)
Eval will always be executed on the primary redis server.
func (*RedisDBConn) HGet ¶
func (clients *RedisDBConn) HGet(c context.Context, key string, field string) (result string, err error)
HGet To get single redis hash key and it's field from redis.
func (*RedisDBConn) HGetAll ¶ added in v2.0.7
func (clients *RedisDBConn) HGetAll(c context.Context, key string) (result map[string]string, err error)
HGet To get all fields with their corresponding values in a hash in a single call to redis.
func (*RedisDBConn) HGets ¶
func (clients *RedisDBConn) HGets(c context.Context, redisKeysWithField map[string]string) (map[string]string, error)
HGets To get one field from multiple redis hashes in one call to redis. Input is a map of keys and the respective field for those keys. Output is a map of keys and the respective values for those keys in redis.
func (*RedisDBConn) HSet ¶
func (clients *RedisDBConn) HSet(c context.Context, key string, args ...interface{}) error
- HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"}) - HSet("myhash", []string{"key1", "value1", "key2", "value2"}) - HSet("myhash", "key1", "value1", "key2", "value2")
func (*RedisDBConn) IncrementValue ¶
func (clients *RedisDBConn) IncrementValue(c context.Context, key string) error
func (*RedisDBConn) MGet ¶
func (clients *RedisDBConn) MGet(c context.Context, keys ...string) (result []interface{}, err error)
MGet This is a replacement of the original `MGet` method by utilizing the `pipeline` approach when Redis is in `cluster` mode.
func (*RedisDBConn) MSet ¶
func (clients *RedisDBConn) MSet(c context.Context, values ...interface{}) (err error)
MSet This is a replacement of the original `MSet` method by utilizing the `pipeline` approach when Redis is in `cluster` mode. it accepts multiple values:
- RedisMSet("key1", "value1", "key2", "value2")
- RedisMSet([]string{"key1", "value1", "key2", "value2"})
- RedisMSet(map[string]interface{}{"key1": "value1", "key2": "value2"})
For `struct` values, please implement the `encoding.BinaryMarshaler` interface.
func (*RedisDBConn) MSetWithTTL ¶
func (clients *RedisDBConn) MSetWithTTL(c context.Context, ttl time.Duration, values ...interface{}) (err error)
MSetWithTTL This method is implemented using `pipeline`. For accepts multiple values, see RedisMSet description.
func (*RedisDBConn) Pipeline ¶ added in v2.0.8
func (clients *RedisDBConn) Pipeline() redis.Pipeliner
func (*RedisDBConn) Pipelined ¶ added in v2.0.3
func (clients *RedisDBConn) Pipelined(c context.Context, fn func(redis.Pipeliner) error) ([]redis.Cmder, error)
func (*RedisDBConn) Run ¶ added in v2.3.0
func (clients *RedisDBConn) Run(ctx context.Context, script *redis.Script, keys []string, args ...interface{}) (interface{}, error)
Run wraps redis.Script.
func (*RedisDBConn) SAdd ¶
func (clients *RedisDBConn) SAdd(c context.Context, key string, elements interface{}) error
func (*RedisDBConn) SRandMemberN ¶
func (*RedisDBConn) SRem ¶
func (clients *RedisDBConn) SRem(c context.Context, key string, elements interface{}) error
type TenantConnections ¶
type TenantConnections struct { ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:Id"` UUID string `gorm:"type:CHAR(36);not null;unique;column:Uuid"` TenantID uint64 `gorm:"not null;column:TenantId"` Code string `gorm:"type:VARCHAR(20);not null;unique;column:Code"` Connections datatypes.JSON `gorm:"not null;column:Connections"` CreatedBy uint64 `gorm:"not null;default:0;column:CreatedBy"` UpdatedBy uint64 `gorm:"not null;default:0;column:UpdatedBy"` DeletedBy uint64 `gorm:"default:NULL;column:DeletedBy"` CreatedAt time.Time `gorm:"type:timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;column:CreatedAt"` UpdatedAt time.Time `gorm:"type:timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;column:UpdatedAt"` DeletedAt gorm.DeletedAt `gorm:"type:timestamp NULL DEFAULT NULL;column:DeletedAt"` }
TenantConnections represent a tenant database configuration record in master database
func GetAllTenantCfgs ¶
func GetAllTenantCfgs(db *gorm.DB) []*TenantConnections
GetAllTenantCfgs return all Tenant data from master db.
func (TenantConnections) TableName ¶
func (TenantConnections) TableName() string