mirror of
https://github.com/redis/go-redis.git
synced 2025-04-17 20:17:02 +03:00
Merge branch 'master' into ndyakov/token-based-auth
This commit is contained in:
commit
c248425ade
1
.github/wordlist.txt
vendored
1
.github/wordlist.txt
vendored
@ -29,6 +29,7 @@ Lua
|
||||
MSSQL
|
||||
namespace
|
||||
NoSQL
|
||||
OpenTelemetry
|
||||
ORM
|
||||
Packagist
|
||||
PhpRedis
|
||||
|
39
README.md
39
README.md
@ -167,6 +167,24 @@ func ExampleClient() *redis.Client {
|
||||
|
||||
```
|
||||
|
||||
### Instrument with OpenTelemetry
|
||||
|
||||
```go
|
||||
import (
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/redis/go-redis/extra/redisotel/v9"
|
||||
"errors"
|
||||
)
|
||||
|
||||
func main() {
|
||||
...
|
||||
rdb := redis.NewClient(&redis.Options{...})
|
||||
|
||||
if err := errors.Join(redisotel.InstrumentTracing(rdb), redisotel.InstrumentMetrics(rdb)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
@ -215,9 +233,26 @@ val1 := client.FTSearchWithArgs(ctx, "txt", "foo bar", &redis.FTSearchOptions{})
|
||||
|
||||
In the Redis-Search module, **the default dialect is 2**. If needed, you can explicitly specify a different dialect using the appropriate configuration in your queries.
|
||||
|
||||
## Contributing
|
||||
**Important**: Be aware that the query dialect may impact the results returned. If needed, you can revert to a different dialect version by passing the desired dialect in the arguments of the command you want to execute.
|
||||
For example:
|
||||
```
|
||||
res2, err := rdb.FTSearchWithArgs(ctx,
|
||||
"idx:bicycle",
|
||||
"@pickup_zone:[CONTAINS $bike]",
|
||||
&redis.FTSearchOptions{
|
||||
Params: map[string]interface{}{
|
||||
"bike": "POINT(-0.1278 51.5074)",
|
||||
},
|
||||
DialectVersion: 3,
|
||||
},
|
||||
).Result()
|
||||
```
|
||||
You can find further details in the [query dialect documentation](https://redis.io/docs/latest/develop/interact/search-and-query/advanced-concepts/dialects/).
|
||||
|
||||
Please see [out contributing guidelines](CONTRIBUTING.md) to help us improve this library!
|
||||
## Contributing
|
||||
We welcome contributions to the go-redis library! If you have a bug fix, feature request, or improvement, please open an issue or pull request on GitHub.
|
||||
We appreciate your help in making go-redis better for everyone.
|
||||
If you are interested in contributing to the go-redis library, please check out our [contributing guidelines](CONTRIBUTING.md) for more information on how to get started.
|
||||
|
||||
## Look and feel
|
||||
|
||||
|
@ -422,6 +422,12 @@ func (c cmdable) Ping(ctx context.Context) *StatusCmd {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c cmdable) Do(ctx context.Context, args ...interface{}) *Cmd {
|
||||
cmd := NewCmd(ctx, args...)
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c cmdable) Quit(_ context.Context) *StatusCmd {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
@ -84,6 +84,12 @@ var _ = Describe("Commands", func() {
|
||||
Expect(ping.Val()).To(Equal("PONG"))
|
||||
})
|
||||
|
||||
It("should Ping with Do method", func() {
|
||||
result := client.Conn().Do(ctx, "PING")
|
||||
Expect(result.Err()).NotTo(HaveOccurred())
|
||||
Expect(result.Val()).To(Equal("PONG"))
|
||||
})
|
||||
|
||||
It("should Wait", func() {
|
||||
const wait = 3 * time.Second
|
||||
|
||||
|
323
doctests/cmds_list_test.go
Normal file
323
doctests/cmds_list_test.go
Normal file
@ -0,0 +1,323 @@
|
||||
// EXAMPLE: cmds_list
|
||||
// HIDE_START
|
||||
package example_commands_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// HIDE_END
|
||||
|
||||
func ExampleClient_cmd_llen() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "mylist")
|
||||
// REMOVE_END
|
||||
|
||||
// STEP_START llen
|
||||
lPushResult1, err := rdb.LPush(ctx, "mylist", "World").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lPushResult1) // >>> 1
|
||||
|
||||
lPushResult2, err := rdb.LPush(ctx, "mylist", "Hello").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lPushResult2) // >>> 2
|
||||
|
||||
lLenResult, err := rdb.LLen(ctx, "mylist").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lLenResult) // >>> 2
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// 1
|
||||
// 2
|
||||
// 2
|
||||
}
|
||||
func ExampleClient_cmd_lpop() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "mylist")
|
||||
// REMOVE_END
|
||||
|
||||
// STEP_START lpop
|
||||
RPushResult, err := rdb.RPush(ctx,
|
||||
"mylist", "one", "two", "three", "four", "five",
|
||||
).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(RPushResult) // >>> 5
|
||||
|
||||
lPopResult, err := rdb.LPop(ctx, "mylist").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lPopResult) // >>> one
|
||||
|
||||
lPopCountResult, err := rdb.LPopCount(ctx, "mylist", 2).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lPopCountResult) // >>> [two three]
|
||||
|
||||
lRangeResult, err := rdb.LRange(ctx, "mylist", 0, -1).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lRangeResult) // >>> [four five]
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// 5
|
||||
// one
|
||||
// [two three]
|
||||
// [four five]
|
||||
}
|
||||
|
||||
func ExampleClient_cmd_lpush() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "mylist")
|
||||
// REMOVE_END
|
||||
|
||||
// STEP_START lpush
|
||||
lPushResult1, err := rdb.LPush(ctx, "mylist", "World").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lPushResult1) // >>> 1
|
||||
|
||||
lPushResult2, err := rdb.LPush(ctx, "mylist", "Hello").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lPushResult2) // >>> 2
|
||||
|
||||
lRangeResult, err := rdb.LRange(ctx, "mylist", 0, -1).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lRangeResult) // >>> [Hello World]
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// 1
|
||||
// 2
|
||||
// [Hello World]
|
||||
}
|
||||
|
||||
func ExampleClient_cmd_lrange() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "mylist")
|
||||
// REMOVE_END
|
||||
|
||||
// STEP_START lrange
|
||||
RPushResult, err := rdb.RPush(ctx, "mylist",
|
||||
"one", "two", "three",
|
||||
).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(RPushResult) // >>> 3
|
||||
|
||||
lRangeResult1, err := rdb.LRange(ctx, "mylist", 0, 0).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lRangeResult1) // >>> [one]
|
||||
|
||||
lRangeResult2, err := rdb.LRange(ctx, "mylist", -3, 2).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lRangeResult2) // >>> [one two three]
|
||||
|
||||
lRangeResult3, err := rdb.LRange(ctx, "mylist", -100, 100).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lRangeResult3) // >>> [one two three]
|
||||
|
||||
lRangeResult4, err := rdb.LRange(ctx, "mylist", 5, 10).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lRangeResult4) // >>> []
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// 3
|
||||
// [one]
|
||||
// [one two three]
|
||||
// [one two three]
|
||||
// []
|
||||
}
|
||||
|
||||
func ExampleClient_cmd_rpop() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "mylist")
|
||||
// REMOVE_END
|
||||
|
||||
// STEP_START rpop
|
||||
rPushResult, err := rdb.RPush(ctx, "mylist",
|
||||
"one", "two", "three", "four", "five",
|
||||
).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(rPushResult) // >>> 5
|
||||
|
||||
rPopResult, err := rdb.RPop(ctx, "mylist").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(rPopResult) // >>> five
|
||||
|
||||
rPopCountResult, err := rdb.RPopCount(ctx, "mylist", 2).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(rPopCountResult) // >>> [four three]
|
||||
|
||||
lRangeResult, err := rdb.LRange(ctx, "mylist", 0, -1).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lRangeResult) // >>> [one two]
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// 5
|
||||
// five
|
||||
// [four three]
|
||||
// [one two]
|
||||
}
|
||||
|
||||
func ExampleClient_cmd_rpush() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "mylist")
|
||||
// REMOVE_END
|
||||
|
||||
// STEP_START rpush
|
||||
rPushResult1, err := rdb.RPush(ctx, "mylist", "Hello").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(rPushResult1) // >>> 1
|
||||
|
||||
rPushResult2, err := rdb.RPush(ctx, "mylist", "World").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(rPushResult2) // >>> 2
|
||||
|
||||
lRangeResult, err := rdb.LRange(ctx, "mylist", 0, -1).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(lRangeResult) // >>> [Hello World]
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// 1
|
||||
// 2
|
||||
// [Hello World]
|
||||
}
|
@ -5,7 +5,7 @@ go 1.18
|
||||
replace github.com/redis/go-redis/v9 => ../..
|
||||
|
||||
require (
|
||||
github.com/redis/go-redis/v9 v9.7.3
|
||||
github.com/redis/go-redis/v9 v9.8.0-beta.1
|
||||
go.uber.org/zap v1.24.0
|
||||
)
|
||||
|
||||
|
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
replace github.com/redis/go-redis/v9 => ../..
|
||||
|
||||
require github.com/redis/go-redis/v9 v9.7.3
|
||||
require github.com/redis/go-redis/v9 v9.8.0-beta.1
|
||||
|
||||
require (
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
|
@ -6,7 +6,7 @@ replace github.com/redis/go-redis/v9 => ../..
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
github.com/redis/go-redis/v9 v9.6.2
|
||||
github.com/redis/go-redis/v9 v9.8.0-beta.1
|
||||
)
|
||||
|
||||
require (
|
||||
|
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
replace github.com/redis/go-redis/v9 => ../..
|
||||
|
||||
require github.com/redis/go-redis/v9 v9.7.3
|
||||
require github.com/redis/go-redis/v9 v9.8.0-beta.1
|
||||
|
||||
require (
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
|
@ -11,8 +11,8 @@ replace github.com/redis/go-redis/extra/redisotel/v9 => ../../extra/redisotel
|
||||
replace github.com/redis/go-redis/extra/rediscmd/v9 => ../../extra/rediscmd
|
||||
|
||||
require (
|
||||
github.com/redis/go-redis/extra/redisotel/v9 v9.7.3
|
||||
github.com/redis/go-redis/v9 v9.7.3
|
||||
github.com/redis/go-redis/extra/redisotel/v9 v9.8.0-beta.1
|
||||
github.com/redis/go-redis/v9 v9.8.0-beta.1
|
||||
github.com/uptrace/uptrace-go v1.21.0
|
||||
go.opentelemetry.io/otel v1.22.0
|
||||
)
|
||||
@ -25,7 +25,7 @@ require (
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
|
||||
github.com/redis/go-redis/extra/rediscmd/v9 v9.7.3 // indirect
|
||||
github.com/redis/go-redis/extra/rediscmd/v9 v9.8.0-beta.1 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.46.1 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.44.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
|
||||
|
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
replace github.com/redis/go-redis/v9 => ../..
|
||||
|
||||
require github.com/redis/go-redis/v9 v9.7.3
|
||||
require github.com/redis/go-redis/v9 v9.8.0-beta.1
|
||||
|
||||
require (
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
|
@ -6,7 +6,7 @@ replace github.com/redis/go-redis/v9 => ../..
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
github.com/redis/go-redis/v9 v9.7.3
|
||||
github.com/redis/go-redis/v9 v9.8.0-beta.1
|
||||
)
|
||||
|
||||
require (
|
||||
|
@ -7,8 +7,8 @@ replace github.com/redis/go-redis/v9 => ../..
|
||||
replace github.com/redis/go-redis/extra/rediscmd/v9 => ../rediscmd
|
||||
|
||||
require (
|
||||
github.com/redis/go-redis/extra/rediscmd/v9 v9.7.3
|
||||
github.com/redis/go-redis/v9 v9.7.3
|
||||
github.com/redis/go-redis/extra/rediscmd/v9 v9.8.0-beta.1
|
||||
github.com/redis/go-redis/v9 v9.8.0-beta.1
|
||||
go.opencensus.io v0.24.0
|
||||
)
|
||||
|
||||
|
@ -7,7 +7,7 @@ replace github.com/redis/go-redis/v9 => ../..
|
||||
require (
|
||||
github.com/bsm/ginkgo/v2 v2.12.0
|
||||
github.com/bsm/gomega v1.27.10
|
||||
github.com/redis/go-redis/v9 v9.7.3
|
||||
github.com/redis/go-redis/v9 v9.8.0-beta.1
|
||||
)
|
||||
|
||||
require (
|
||||
|
@ -7,8 +7,8 @@ replace github.com/redis/go-redis/v9 => ../..
|
||||
replace github.com/redis/go-redis/extra/rediscmd/v9 => ../rediscmd
|
||||
|
||||
require (
|
||||
github.com/redis/go-redis/extra/rediscmd/v9 v9.7.3
|
||||
github.com/redis/go-redis/v9 v9.7.3
|
||||
github.com/redis/go-redis/extra/rediscmd/v9 v9.8.0-beta.1
|
||||
github.com/redis/go-redis/v9 v9.8.0-beta.1
|
||||
go.opentelemetry.io/otel v1.22.0
|
||||
go.opentelemetry.io/otel/metric v1.22.0
|
||||
go.opentelemetry.io/otel/sdk v1.22.0
|
||||
|
@ -6,7 +6,7 @@ replace github.com/redis/go-redis/v9 => ../..
|
||||
|
||||
require (
|
||||
github.com/prometheus/client_golang v1.14.0
|
||||
github.com/redis/go-redis/v9 v9.7.3
|
||||
github.com/redis/go-redis/v9 v9.8.0-beta.1
|
||||
)
|
||||
|
||||
require (
|
||||
|
@ -2,5 +2,5 @@ package redis
|
||||
|
||||
// Version is the current release version.
|
||||
func Version() string {
|
||||
return "9.7.3"
|
||||
return "9.8.0-beta.1"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user