Documentation ¶
Index ¶
- func CtxWithHBase(ctx context.Context, hbase hbase.Client) context.Context
- func CtxWithRedis(ctx context.Context, redis *redisv8.Client) context.Context
- func GetDBFromCtx(ctx context.Context) *gorm.DB
- func GetHBaseFromCtx(ctx context.Context) hbase.Client
- func GetRedisFromCtx(ctx context.Context) *redisv8.Client
- func IsInTransaction(ctx context.Context) bool
- func Pipeline(ctx context.Context, fn func(pipeline redisv8.Pipeliner) error) error
- func Transaction(ctx context.Context, f func(context.Context) error) error
- func TxPipeline(ctx context.Context, fn func(pipeline redisv8.Pipeliner) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CtxWithHBase ¶ added in v0.0.6
CtxWithHBase return new context.Context contain value with gohbase.Client
func CtxWithRedis ¶ added in v0.0.6
CtxWithRedis return new context.Context contain value with redisv8.Client
func GetDBFromCtx ¶
GetDBFromCtx try to get gorm.DB from context, if not found then return DB with context.Background
func GetHBaseFromCtx ¶ added in v0.0.6
GetHBaseFromCtx try to get gohbase.Client from context, if not found then return defaultHBaseClient
func GetRedisFromCtx ¶ added in v0.0.6
GetRedisFromCtx try to get redisv8.Client from context, if not found then return defaultRedisClient
func IsInTransaction ¶
IsInTransaction return true if current operation within a transaction
func Pipeline ¶ added in v0.0.6
Pipeline get redisv8.Client from ctx and run Pipeline Operation with ctx
func Transaction ¶
Transaction get gorm.DB from ctx and run Transaction Operation with ctx How to use:
// 所有 db 操作的第一参数为 context.Context, 然后通过 ctx 读取 DB 对象 if err := db.Transaction(context.Background(), func(ctx context.Context) error { if err := d.Create(ctx); err != nil { return err } d.Name = "123" return d.Update(ctx) }); err != nil { return } func (d *Domain) Create(ctx context.Context) error { return GetDBFromCtx(ctx).Create(d).Error } func (d *Domain) Update(ctx context.Context) error { return GetDBFromCtx(ctx).Updates(d).Error }
func TxPipeline ¶ added in v0.0.6
TxPipeline get redisv8.Client from ctx and run Transaction Pipeline Operation with ctx
It's same as Pipeline, but wraps queued commands with MULTI/EXEC.
How to use: var (
get *redisv8.StringCmd ) err := TxPipeline(ctx, func(pipeline redisv8.Pipeliner) error { pipeline.Set(ctx, "key", "value", 0) get = pipeline.Get(ctx, "key") return nil }) if err != nil { return err } fmt.Println(get.Val()) // Output: value
Types ¶
This section is empty.