-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add SetContext support for go-redis without losing redigo
- Loading branch information
Showing
5 changed files
with
182 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package rejson | ||
|
||
import ( | ||
"context" | ||
"github.com/nitishm/go-rejson/clients" | ||
"github.com/nitishm/go-rejson/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 | ||
} |
Oops, something went wrong.