1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-31 05:04:23 +03:00

sync master (#1800)

* Remove OpenTelemetry from the code (but leave redisotel as is) (#1782)

* Add XAutoClaim command (#1780)

* fix typo (#1788)

* xgroup/xadd/xtrim supports new options (#1787)

* support cmd option

XGROUP CREATECONSUMER
XTRIM MINID LIMIT
XADD NOMKSTREAM MINID LIMIT

Signed-off-by: monkey <golang@88.com>

* add XAddArgs.Approx doc

Signed-off-by: monkey92t <golang@88.com>

* Add Bun to readme

* Upgrade the <sorted set> series of commands (#1792)

* Upgrade the <sorted set> series of commands

Signed-off-by: monkey92t <golang@88.com>

* Cancel the Deprecated mark of ZAddNX and ZAddXX

Signed-off-by: monkey92t <golang@88.com>

* Explain the use restrictions of KeepTTL. (#1799)

Signed-off-by: monkey92t <golang@88.com>

* Adjust KeepTTL annotation.

Signed-off-by: monkey92t <golang@88.com>

* the hello command throws possible errors, It may affect the "read timeout" test result.

Signed-off-by: monkey92t <golang@88.com>

Co-authored-by: Vladimir Mihailenco <vladimir.webdev@gmail.com>
Co-authored-by: ericmillin <31105612+ericmillin@users.noreply.github.com>
Co-authored-by: heyanfu <1145291570@qq.com>
This commit is contained in:
monkey92t
2021-06-28 17:40:38 +08:00
committed by GitHub
parent bd6402ab3e
commit 63df0e5e75
13 changed files with 951 additions and 452 deletions

View File

@ -49,7 +49,7 @@ var (
func Struct(dst interface{}) (StructValue, error) {
v := reflect.ValueOf(dst)
// The dstination to scan into should be a struct pointer.
// The destination to scan into should be a struct pointer.
if v.Kind() != reflect.Ptr || v.IsNil() {
return StructValue{}, fmt.Errorf("redis.Scan(non-pointer %T)", dst)
}

View File

@ -65,26 +65,17 @@ func (cn *Conn) RemoteAddr() net.Addr {
}
func (cn *Conn) WithReader(ctx context.Context, timeout time.Duration, fn func(rd *proto.Reader) error) error {
ctx, span := internal.StartSpan(ctx, "redis.with_reader")
defer span.End()
if err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout)); err != nil {
return internal.RecordError(ctx, span, err)
return err
}
if err := fn(cn.rd); err != nil {
return internal.RecordError(ctx, span, err)
}
return nil
return fn(cn.rd)
}
func (cn *Conn) WithWriter(
ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error,
) error {
ctx, span := internal.StartSpan(ctx, "redis.with_writer")
defer span.End()
if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil {
return internal.RecordError(ctx, span, err)
return err
}
if cn.bw.Buffered() > 0 {
@ -92,11 +83,11 @@ func (cn *Conn) WithWriter(
}
if err := fn(cn.wr); err != nil {
return internal.RecordError(ctx, span, err)
return err
}
if err := cn.bw.Flush(); err != nil {
return internal.RecordError(ctx, span, err)
return err
}
internal.WritesCounter.Add(ctx, 1)

View File

@ -4,16 +4,10 @@ import (
"context"
"time"
"github.com/go-redis/redis/v8/internal/proto"
"github.com/go-redis/redis/v8/internal/util"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)
func Sleep(ctx context.Context, dur time.Duration) error {
_, span := StartSpan(ctx, "time.Sleep")
defer span.End()
t := time.NewTimer(dur)
defer t.Stop()
@ -50,21 +44,3 @@ func isLower(s string) bool {
}
return true
}
//------------------------------------------------------------------------------
var tracer = otel.Tracer("github.com/go-redis/redis")
func StartSpan(ctx context.Context, name string) (context.Context, trace.Span) {
if span := trace.SpanFromContext(ctx); !span.IsRecording() {
return ctx, span
}
return tracer.Start(ctx, name)
}
func RecordError(ctx context.Context, span trace.Span, err error) error {
if err != proto.Nil {
span.RecordError(err)
}
return err
}