-
Notifications
You must be signed in to change notification settings - Fork 47
/
context.go
30 lines (26 loc) · 837 Bytes
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package rejson
import (
"context"
"github.com/nitishm/go-rejson/v4/clients"
"github.com/nitishm/go-rejson/v4/rjs"
)
// SetContext helps redis-clients, provide use of command level context
// in the ReJSON commands.
// Currently, only go-redis@v8 supports command level context, therefore
// a separate method is added to support it, maintaining the support for
// other clients and for backward compatibility. (nitishm/go-rejson#46)
func (r *Handler) SetContext(ctx context.Context) *Handler {
if r == nil {
return r // nil
}
if r.clientName == rjs.ClientGoRedis {
if old, ok := r.implementation.(*clients.GoRedis); ok {
return &Handler{
clientName: r.clientName,
implementation: clients.NewGoRedisClient(ctx, old.Conn),
}
}
}
// for other clients, context is of no use, hence return same
return r
}