go-redis/redis · error

redis: no initConnFunc set for conn

Error message

redis: no initConnFunc set for conn[%d]

What it means

Error "redis: no initConnFunc set for conn[%d]" thrown in go-redis/redis.

Solutions

  1. Construct connections through the pool's NewConnPool so initConnFunc is wired
  2. If constructing pool.Conn manually, set the init function before first use

When it happens

Trigger: Thrown at internal/pool/conn.go:693 when the library encounters an invalid state.

Common situations: Never construct pool connections outside the pool factory.


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /api/errors/318994faa1131432. Report an issue: GitHub.

Appendix: source

Thrown at internal/pool/conn.go:693

}

// SetOnCscReinit sets the client-side-caching pre-reinitialization hook,
// overwriting any previous one.
func (cn *Conn) SetOnCscReinit(fn func()) {
	cn.onCscReinit = fn
}

// SetInitConnFunc sets the connection initialization function to be called on reconnections.
func (cn *Conn) SetInitConnFunc(fn func(context.Context, *Conn) error) {
	cn.initConnFunc = fn
}

// ExecuteInitConn runs the stored connection initialization function if available.
func (cn *Conn) ExecuteInitConn(ctx context.Context) error {
	if cn.initConnFunc != nil {
		return cn.initConnFunc(ctx, cn)
	}
	return fmt.Errorf("redis: no initConnFunc set for conn[%d]", cn.GetID())
}

func (cn *Conn) SetNetConn(netConn net.Conn) {
	// Store the new connection atomically first (lock-free)
	cn.setNetConn(netConn)
	// Protect reader reset operations to avoid data races
	// Use write lock since we're modifying the reader state
	cn.readerMu.Lock()
	cn.rd.Reset(netConn)
	cn.readerMu.Unlock()

	cn.bw.Reset(netConn)

	// A new socket is a new server session with no HIMPORT fieldsets and
	// nothing left to discard.
	cn.ClearPreparedFieldsets(0)
}

View on GitHub (pinned to 36d97525cd)