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

Method TryAcquire

internal/pool/conn.go:810–814  ·  view source on GitHub ↗

TryAcquire attempts to acquire the connection for use. This is an optimized inline method for the hot path (Get operation). It tries to transition from IDLE -> IN_USE or CREATED -> CREATED. Returns true if the connection was successfully acquired, false otherwise. The CREATED->CREATED is done so we

()

Source from the content-addressed store, hash-verified

808// waiter notification, and benchmarks show 1-3% improvement. If the state machine ever
809// needs to notify waiters on these transitions, update this to use TryTransitionFast().
810func (cn *Conn) TryAcquire() bool {
811 // The || operator short-circuits, so only 1 CAS in the common case
812 return cn.stateMachine.state.CompareAndSwap(uint32(StateIdle), uint32(StateInUse)) ||
813 cn.stateMachine.state.CompareAndSwap(uint32(StateCreated), uint32(StateCreated))
814}
815
816// Release releases the connection back to the pool.
817// This is an optimized inline method for the hot path (Put operation).

Callers 4

popIdleMethod · 0.95
_getConnMethod · 0.45
checkMinIdleConnsMethod · 0.45
waitTurnMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected