1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Add helpers to set libinfo without panic (#2724)

* add helpers to set library name and library info without risk of panic if we try to set both

* refactor code to use helpers

* add example

* refactor tests

* fix testable example

* simplify example

* rename exampl

* fix ring.go

* update example

---------

Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com>
This commit is contained in:
Tiago Peczenyj
2024-02-14 21:40:20 +01:00
committed by GitHub
parent 7b9e81fd41
commit 21ed15bbed
4 changed files with 38 additions and 7 deletions

View File

@ -154,7 +154,7 @@ func ExampleClient() {
// missing_key does not exist
}
func ExampleConn() {
func ExampleConn_name() {
conn := rdb.Conn()
err := conn.ClientSetName(ctx, "foobar").Err()
@ -175,6 +175,28 @@ func ExampleConn() {
// Output: foobar
}
func ExampleConn_client_setInfo_libraryVersion() {
conn := rdb.Conn()
err := conn.ClientSetInfo(ctx, redis.WithLibraryVersion("1.2.3")).Err()
if err != nil {
panic(err)
}
// Open other connections.
for i := 0; i < 10; i++ {
go rdb.Ping(ctx)
}
s, err := conn.ClientInfo(ctx).Result()
if err != nil {
panic(err)
}
fmt.Println(s.LibVer)
// Output: 1.2.3
}
func ExampleClient_Set() {
// Last argument is expiration. Zero means the key has no
// expiration time.