go-redis icon indicating copy to clipboard operation
go-redis copied to clipboard

Add support for update cmd in the hooks

Open haijianyang opened this issue 2 years ago • 0 comments

In multi tenant SasS system, I want to update cmd before process.

type RedisHooks struct {}

func (h *RedisHooks) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error) {
	tenantID, ok := ctx.Value(TenantKey{}).(string)
	if !ok {
		return ctx, nil
	}

	// Update cmd there.
	// For example: when use redis.set, could set newKey = tenantID + oldKey

	return ctx, nil
}

haijianyang avatar Dec 29 '21 10:12 haijianyang