MCPcopy
hub / github.com/redis/go-redis / SetUsable

Method SetUsable

internal/pool/conn.go:297–305  ·  view source on GitHub ↗

SetUsable sets the usable flag for the connection (lock-free). Deprecated: Use GetStateMachine().Transition() directly for better state management. This method is kept for backwards compatibility. This should be called to mark a connection as usable after initialization or to release it after a ba

(usable bool)

Source from the content-addressed store, hash-verified

295// Prefer CompareAndSwapUsable() when acquiring exclusive access to avoid race conditions.
296// Deprecated: Use GetStateMachine().Transition() directly for better state management.
297func (cn *Conn) SetUsable(usable bool) {
298 if usable {
299 // Transition to IDLE state (ready to be acquired)
300 cn.stateMachine.Transition(StateIdle)
301 } else {
302 // Transition to UNUSABLE state (for background operations)
303 cn.stateMachine.Transition(StateUnusable)
304 }
305}
306
307// IsInited returns true if the connection has been initialized.
308// This is a backward-compatible wrapper around the state machine.

Callers 3

createMockPoolConnectionFunction · 0.95
TestConnectionHookFunction · 0.95
TestConn_UsableUnusableFunction · 0.95

Calls 1

TransitionMethod · 0.80

Tested by 3

createMockPoolConnectionFunction · 0.76
TestConnectionHookFunction · 0.76
TestConn_UsableUnusableFunction · 0.76