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

Method WithWriter

internal/pool/conn.go:910–940  ·  internal/pool/conn.go::Conn.WithWriter
(
	ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error,
)

Source from the content-addressed store, hash-verified

908}
909
910func (cn *Conn) WithWriter(
911 ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error,
912) error {
913 if timeout >= 0 {
914 // Use relaxed timeout if set, otherwise use provided timeout
915 effectiveTimeout := cn.getEffectiveWriteTimeout(timeout)
916
917 // Set write deadline on the connection
918 if netConn := cn.getNetConn(); netConn != nil {
919 if err := netConn.SetWriteDeadline(cn.deadline(ctx, effectiveTimeout)); err != nil {
920 return err
921 }
922 } else {
923 // Connection is not available - return preallocated error
924 return errConnNotAvailableForWrite
925 }
926 }
927
928 // Reset the buffered writer if needed, should not happen
929 if cn.bw.Buffered() > 0 {
930 if netConn := cn.getNetConn(); netConn != nil {
931 cn.bw.Reset(netConn)
932 }
933 }
934
935 if err := fn(cn.wr); err != nil {
936 return err
937 }
938
939 return cn.bw.Flush()
940}
941
942func (cn *Conn) IsClosed() bool {
943 return cn.stateMachine.GetState() == StateClosed

Callers 8

_processMethod · 0.80
pipelineProcessCmdsMethod · 0.80
txPipelineProcessCmdsMethod · 0.80
writeCmdMethod · 0.80

Calls 6

getNetConnMethod · 0.95
deadlineMethod · 0.95
BufferedMethod · 0.80
SetWriteDeadlineMethod · 0.45
ResetMethod · 0.45

Tested by 2