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

Method IsUsable

internal/pool/conn.go:278–285  ·  view source on GitHub ↗

IsUsable returns true if the connection is safe to use for new commands (lock-free). A connection is "usable" when it's in a stable state and can be returned to clients. It becomes unusable during: - Handoff operations (network connection replacement) - Re-authentication (credential updates) - Othe

()

Source from the content-addressed store, hash-verified

276// Note: CREATED state is considered usable because new connections need to pass OnGet() hook
277// before initialization. The initialization happens after OnGet() in the client code.
278func (cn *Conn) IsUsable() bool {
279 state := cn.stateMachine.GetState()
280 // CREATED, IDLE, and IN_USE states are considered usable
281 // CREATED: new connection, not yet initialized (will be initialized by client)
282 // IDLE: initialized and ready to be acquired
283 // IN_USE: usable but currently acquired by someone
284 return state == StateCreated || state == StateIdle || state == StateInUse
285}
286
287// SetUsable sets the usable flag for the connection (lock-free).
288//

Callers 6

TestConnectionHookFunction · 0.95
TestConn_UsableUnusableFunction · 0.95
releaseConnMethod · 0.80
OnGetMethod · 0.80
putConnMethod · 0.80
pool_test.goFile · 0.80

Calls 1

GetStateMethod · 0.45

Tested by 2

TestConnectionHookFunction · 0.76
TestConn_UsableUnusableFunction · 0.76