[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-4792":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":22,"hasPages":22,"topics":24,"createdAt":10,"pushedAt":10,"updatedAt":29,"readmeContent":30,"aiSummary":31,"trendingCount":16,"starSnapshotCount":16,"syncStatus":32,"lastSyncTime":33,"discoverSource":34},4792,"go-redis","redis\u002Fgo-redis","redis","Redis Go client","https:\u002F\u002Fredis.io",null,"Go",22135,2558,253,30,0,11,62,3,45,"BSD 2-Clause \"Simplified\" License",false,"master",[25,26,7,27,28],"go","golang","redis-client","redis-cluster","2026-06-12 02:01:03","# Redis client for Go\n\n[![build workflow](https:\u002F\u002Fgithub.com\u002Fredis\u002Fgo-redis\u002Factions\u002Fworkflows\u002Fbuild.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fredis\u002Fgo-redis\u002Factions)\n[![PkgGoDev](https:\u002F\u002Fpkg.go.dev\u002Fbadge\u002Fgithub.com\u002Fredis\u002Fgo-redis\u002Fv9)](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fredis\u002Fgo-redis\u002Fv9?tab=doc)\n[![Documentation](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fredis-documentation-informational)](https:\u002F\u002Fredis.io\u002Fdocs\u002Flatest\u002Fdevelop\u002Fclients\u002Fgo\u002F)\n[![Go Report Card](https:\u002F\u002Fgoreportcard.com\u002Fbadge\u002Fgithub.com\u002Fredis\u002Fgo-redis\u002Fv9)](https:\u002F\u002Fgoreportcard.com\u002Freport\u002Fgithub.com\u002Fredis\u002Fgo-redis\u002Fv9)\n[![codecov](https:\u002F\u002Fcodecov.io\u002Fgithub\u002Fredis\u002Fgo-redis\u002Fgraph\u002Fbadge.svg?token=tsrCZKuSSw)](https:\u002F\u002Fcodecov.io\u002Fgithub\u002Fredis\u002Fgo-redis)\n\n[![Discord](https:\u002F\u002Fimg.shields.io\u002Fdiscord\u002F697882427875393627.svg?style=social&logo=discord)](https:\u002F\u002Fdiscord.gg\u002FW4txy5AeKM)\n[![Twitch](https:\u002F\u002Fimg.shields.io\u002Ftwitch\u002Fstatus\u002Fredisinc?style=social)](https:\u002F\u002Fwww.twitch.tv\u002Fredisinc)\n[![YouTube](https:\u002F\u002Fimg.shields.io\u002Fyoutube\u002Fchannel\u002Fviews\u002FUCD78lHSwYqMlyetR0_P4Vig?style=social)](https:\u002F\u002Fwww.youtube.com\u002Fredisinc)\n[![Twitter](https:\u002F\u002Fimg.shields.io\u002Ftwitter\u002Ffollow\u002Fredisinc?style=social)](https:\u002F\u002Ftwitter.com\u002Fredisinc)\n[![Stack Exchange questions](https:\u002F\u002Fimg.shields.io\u002Fstackexchange\u002Fstackoverflow\u002Ft\u002Fgo-redis?style=social&logo=stackoverflow&label=Stackoverflow)](https:\u002F\u002Fstackoverflow.com\u002Fquestions\u002Ftagged\u002Fgo-redis)\n\n> go-redis is the official Redis client library for the Go programming language. It offers a straightforward interface for interacting with Redis servers. \n\n## Supported versions\n\nIn `go-redis` we are aiming to support the last three releases of Redis. Currently, this means we do support:\n- [Redis 8.0](https:\u002F\u002Fraw.githubusercontent.com\u002Fredis\u002Fredis\u002F8.0\u002F00-RELEASENOTES) - using Redis CE 8.0\n- [Redis 8.2](https:\u002F\u002Fraw.githubusercontent.com\u002Fredis\u002Fredis\u002F8.2\u002F00-RELEASENOTES) - using Redis CE 8.2 \n- [Redis 8.4](https:\u002F\u002Fraw.githubusercontent.com\u002Fredis\u002Fredis\u002F8.4\u002F00-RELEASENOTES) - using Redis CE 8.4\n\nAlthough the `go.mod` states it requires at minimum `go 1.24`, our CI is configured to run the tests against all three\nversions of Redis and multiple versions of Go ([1.24](https:\u002F\u002Fgo.dev\u002Fdoc\u002Fdevel\u002Frelease#go1.24.0), oldstable, and stable). We observe that some modules related test may not pass with\nRedis Stack 7.2 and some commands are changed with Redis CE 8.0.\nAlthough it is not officially supported, `go-redis\u002Fv9`  should be able to work with any Redis 7.0+.\nPlease do refer to the documentation and the tests if you experience any issues.\n\n## How do I Redis?\n\n[Learn for free at Redis University](https:\u002F\u002Funiversity.redis.com\u002F)\n\n[Build faster with the Redis Launchpad](https:\u002F\u002Flaunchpad.redis.com\u002F)\n\n[Try the Redis Cloud](https:\u002F\u002Fredis.com\u002Ftry-free\u002F)\n\n[Dive in developer tutorials](https:\u002F\u002Fdeveloper.redis.com\u002F)\n\n[Join the Redis community](https:\u002F\u002Fredis.com\u002Fcommunity\u002F)\n\n[Work at Redis](https:\u002F\u002Fredis.com\u002Fcompany\u002Fcareers\u002Fjobs\u002F)\n\n\n## Resources\n\n- [Discussions](https:\u002F\u002Fgithub.com\u002Fredis\u002Fgo-redis\u002Fdiscussions)\n- [Chat](https:\u002F\u002Fdiscord.gg\u002FW4txy5AeKM)\n- [Reference](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fredis\u002Fgo-redis\u002Fv9)\n- [Examples](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fredis\u002Fgo-redis\u002Fv9#pkg-examples)\n\n## old documentation\n\n- [English](https:\u002F\u002Fredis.uptrace.dev)\n- [简体中文](https:\u002F\u002Fredis.uptrace.dev\u002Fzh\u002F)\n\n## Ecosystem\n\n- [Entra ID (Azure AD)](https:\u002F\u002Fgithub.com\u002Fredis\u002Fgo-redis-entraid)\n- [Distributed Locks](https:\u002F\u002Fgithub.com\u002Fbsm\u002Fredislock)\n- [Redis Cache](https:\u002F\u002Fgithub.com\u002Fgo-redis\u002Fcache)\n- [Rate limiting](https:\u002F\u002Fgithub.com\u002Fgo-redis\u002Fredis_rate)\n\n## Features\n\n- Redis commands except QUIT and SYNC.\n- Automatic connection pooling.\n- [StreamingCredentialsProvider (e.g. entra id, oauth)](#1-streaming-credentials-provider-highest-priority) (experimental)\n- [Pub\u002FSub](https:\u002F\u002Fredis.uptrace.dev\u002Fguide\u002Fgo-redis-pubsub.html).\n- [Pipelines and transactions](https:\u002F\u002Fredis.uptrace.dev\u002Fguide\u002Fgo-redis-pipelines.html).\n- [Scripting](https:\u002F\u002Fredis.uptrace.dev\u002Fguide\u002Flua-scripting.html).\n- [Redis Sentinel](https:\u002F\u002Fredis.uptrace.dev\u002Fguide\u002Fgo-redis-sentinel.html).\n- [Redis Cluster](https:\u002F\u002Fredis.uptrace.dev\u002Fguide\u002Fgo-redis-cluster.html).\n- [Redis Performance Monitoring](https:\u002F\u002Fredis.uptrace.dev\u002Fguide\u002Fredis-performance-monitoring.html).\n- [Redis Probabilistic [RedisStack]](https:\u002F\u002Fredis.io\u002Fdocs\u002Fdata-types\u002Fprobabilistic\u002F)\n- [Customizable read and write buffers size.](#custom-buffer-sizes)\n\n## Installation\n\ngo-redis supports 2 last Go versions and requires a Go version with\n[modules](https:\u002F\u002Fgithub.com\u002Fgolang\u002Fgo\u002Fwiki\u002FModules) support. So make sure to initialize a Go\nmodule:\n\n```shell\ngo mod init github.com\u002Fmy\u002Frepo\n```\n\nThen install go-redis\u002F**v9**:\n\n```shell\ngo get github.com\u002Fredis\u002Fgo-redis\u002Fv9\n```\n\n## Quickstart\n\n```go\nimport (\n    \"context\"\n    \"fmt\"\n\n    \"github.com\u002Fredis\u002Fgo-redis\u002Fv9\"\n)\n\nvar ctx = context.Background()\n\nfunc ExampleClient() {\n    rdb := redis.NewClient(&redis.Options{\n        Addr:     \"localhost:6379\",\n        Password: \"\", \u002F\u002F no password set\n        DB:       0,  \u002F\u002F use default DB\n    })\n    defer rdb.Close()\n\n    err := rdb.Set(ctx, \"key\", \"value\", 0).Err()\n    if err != nil {\n        panic(err)\n    }\n\n    val, err := rdb.Get(ctx, \"key\").Result()\n    if err != nil {\n        panic(err)\n    }\n    fmt.Println(\"key\", val)\n\n    val2, err := rdb.Get(ctx, \"key2\").Result()\n    if err == redis.Nil {\n        fmt.Println(\"key2 does not exist\")\n    } else if err != nil {\n        panic(err)\n    } else {\n        fmt.Println(\"key2\", val2)\n    }\n    \u002F\u002F Output: key value\n    \u002F\u002F key2 does not exist\n}\n```\n\n### Dial retries and backoff\n\nConnection establishment can be retried by the connection pool when dialing fails.\n\n- **`DialerRetries`**: maximum number of dial attempts (default: 5).\n- **`DialerRetryTimeout`**: default delay between attempts when no custom backoff is provided (default: 100ms).\n- **`DialerRetryBackoff`**: optional function hook to control the delay between attempts.\n\nExample:\n\n```go\nrdb := redis.NewClient(&redis.Options{\n\tAddr: \"localhost:6379\",\n\n\tDialerRetries:      5,\n\tDialerRetryTimeout: 100 * time.Millisecond, \u002F\u002F used when DialerRetryBackoff is nil\n\n\t\u002F\u002F Optional: exponential backoff with jitter and a cap.\n\tDialerRetryBackoff: redis.DialRetryBackoffExponential(100*time.Millisecond, 2*time.Second),\n})\ndefer rdb.Close()\n```\n\n### Authentication\n\nThe Redis client supports multiple ways to provide authentication credentials, with a clear priority order. Here are the available options:\n\n#### 1. Streaming Credentials Provider (Highest Priority) - Experimental feature\n\nThe streaming credentials provider allows for dynamic credential updates during the connection lifetime. This is particularly useful for managed identity services and token-based authentication.\n\n```go\ntype StreamingCredentialsProvider interface {\n    Subscribe(listener CredentialsListener) (Credentials, UnsubscribeFunc, error)\n}\n\ntype CredentialsListener interface {\n    OnNext(credentials Credentials)  \u002F\u002F Called when credentials are updated\n    OnError(err error)              \u002F\u002F Called when an error occurs\n}\n\ntype Credentials interface {\n    BasicAuth() (username string, password string)\n    RawCredentials() string\n}\n```\n\nExample usage:\n```go\nrdb := redis.NewClient(&redis.Options{\n    Addr: \"localhost:6379\",\n    StreamingCredentialsProvider: &MyCredentialsProvider{},\n})\n```\n\n**Note:** The streaming credentials provider can be used with [go-redis-entraid](https:\u002F\u002Fgithub.com\u002Fredis\u002Fgo-redis-entraid) to enable Entra ID (formerly Azure AD) authentication. This allows for seamless integration with Azure's managed identity services and token-based authentication.\n\nExample with Entra ID:\n```go\nimport (\n    \"github.com\u002Fredis\u002Fgo-redis\u002Fv9\"\n    \"github.com\u002Fredis\u002Fgo-redis-entraid\"\n)\n\n\u002F\u002F Create an Entra ID credentials provider\nprovider := entraid.NewDefaultAzureIdentityProvider()\n\n\u002F\u002F Configure Redis client with Entra ID authentication\nrdb := redis.NewClient(&redis.Options{\n    Addr: \"your-redis-server.redis.cache.windows.net:6380\",\n    StreamingCredentialsProvider: provider,\n    TLSConfig: &tls.Config{\n        MinVersion: tls.VersionTLS12,\n    },\n})\n```\n\n#### 2. Context-based Credentials Provider\n\nThe context-based provider allows credentials to be determined at the time of each operation, using the context.\n\n```go\nrdb := redis.NewClient(&redis.Options{\n    Addr: \"localhost:6379\",\n    CredentialsProviderContext: func(ctx context.Context) (string, string, error) {\n        \u002F\u002F Return username, password, and any error\n        return \"user\", \"pass\", nil\n    },\n})\n```\n\n#### 3. Regular Credentials Provider\n\nA simple function-based provider that returns static credentials.\n\n```go\nrdb := redis.NewClient(&redis.Options{\n    Addr: \"localhost:6379\",\n    CredentialsProvider: func() (string, string) {\n        \u002F\u002F Return username and password\n        return \"user\", \"pass\"\n    },\n})\n```\n\n#### 4. Username\u002FPassword Fields (Lowest Priority)\n\nThe most basic way to provide credentials is through the `Username` and `Password` fields in the options.\n\n```go\nrdb := redis.NewClient(&redis.Options{\n    Addr:     \"localhost:6379\",\n    Username: \"user\",\n    Password: \"pass\",\n})\n```\n\n#### Priority Order\n\nThe client will use credentials in the following priority order:\n1. Streaming Credentials Provider (if set)\n2. Context-based Credentials Provider (if set)\n3. Regular Credentials Provider (if set)\n4. Username\u002FPassword fields (if set)\n\nIf none of these are set, the client will attempt to connect without authentication.\n\n### Protocol Version\n\nThe client supports both RESP2 and RESP3 protocols. You can specify the protocol version in the options:\n\n```go\nrdb := redis.NewClient(&redis.Options{\n    Addr:     \"localhost:6379\",\n    Password: \"\", \u002F\u002F no password set\n    DB:       0,  \u002F\u002F use default DB\n    Protocol: 3,  \u002F\u002F specify 2 for RESP 2 or 3 for RESP 3\n})\n```\n\n### Connecting via a redis url\n\ngo-redis also supports connecting via the\n[redis uri specification](https:\u002F\u002Fgithub.com\u002Fredis\u002Fredis-specifications\u002Ftree\u002Fmaster\u002Furi\u002Fredis.txt).\nThe example below demonstrates how the connection can easily be configured using a string, adhering\nto this specification.\n\n```go\nimport (\n    \"github.com\u002Fredis\u002Fgo-redis\u002Fv9\"\n)\n\nfunc ExampleClient() *redis.Client {\n    url := \"redis:\u002F\u002Fuser:password@localhost:6379\u002F0?protocol=3\"\n    opts, err := redis.ParseURL(url)\n    if err != nil {\n        panic(err)\n    }\n\n    return redis.NewClient(opts)\n}\n\n```\n\n### Instrument with OpenTelemetry\n\n```go\nimport (\n    \"github.com\u002Fredis\u002Fgo-redis\u002Fv9\"\n    \"github.com\u002Fredis\u002Fgo-redis\u002Fextra\u002Fredisotel\u002Fv9\"\n    \"errors\"\n)\n\nfunc main() {\n    ...\n    rdb := redis.NewClient(&redis.Options{...})\n\n    if err := errors.Join(redisotel.InstrumentTracing(rdb), redisotel.InstrumentMetrics(rdb)); err != nil {\n        log.Fatal(err)\n    }\n```\n\n\n### Buffer Size Configuration\n\ngo-redis uses 32KiB read and write buffers by default for optimal performance. For high-throughput applications or large pipelines, you can customize buffer sizes:\n\n```go\nrdb := redis.NewClient(&redis.Options{\n    Addr:            \"localhost:6379\",\n    ReadBufferSize:  1024 * 1024, \u002F\u002F 1MiB read buffer\n    WriteBufferSize: 1024 * 1024, \u002F\u002F 1MiB write buffer\n})\n```\n\n### Advanced Configuration\n\ngo-redis supports extending the client identification phase to allow projects to send their own custom client identification.\n\n#### Default Client Identification\n\nBy default, go-redis automatically sends the client library name and version during the connection process. This feature is available in redis-server as of version 7.2. As a result, the command is \"fire and forget\", meaning it should fail silently, in the case that the redis server does not support this feature.\n\n#### Disabling Identity Verification\n\nWhen connection identity verification is not required or needs to be explicitly disabled, a `DisableIdentity` configuration option exists.\nInitially there was a typo and the option was named `DisableIndentity` instead of `DisableIdentity`. The misspelled option is marked as Deprecated and will be removed in V10 of this library.\nAlthough both options will work at the moment, the correct option is `DisableIdentity`. The deprecated option will be removed in V10 of this library, so please use the correct option name to avoid any issues.\n\nTo disable verification, set the `DisableIdentity` option to `true` in the Redis client options:\n\n```go\nrdb := redis.NewClient(&redis.Options{\n    Addr:            \"localhost:6379\",\n    Password:        \"\",\n    DB:              0,\n    DisableIdentity: true, \u002F\u002F Disable set-info on connect\n})\n```\n\n#### Unstable RESP3 Structures for RediSearch Commands\nWhen integrating Redis with application functionalities using RESP3, it's important to note that some response structures aren't final yet. This is especially true for more complex structures like search and query results. We recommend using RESP2 when using the search and query capabilities, but we plan to stabilize the RESP3-based API-s in the coming versions. You can find more guidance in the upcoming release notes.\n\nTo enable unstable RESP3, set the option in your client configuration:\n\n```go\nredis.NewClient(&redis.Options{\n\t\t\tUnstableResp3: true,\n\t\t})\n```\n**Note:** When UnstableResp3 mode is enabled, it's necessary to use RawResult() and RawVal() to retrieve a raw data.\n          Since, raw response is the only option for unstable search commands Val() and Result() calls wouldn't have any affect on them:\n\n```go\nres1, err := client.FTSearchWithArgs(ctx, \"txt\", \"foo bar\", &redis.FTSearchOptions{}).RawResult()\nval1 := client.FTSearchWithArgs(ctx, \"txt\", \"foo bar\", &redis.FTSearchOptions{}).RawVal()\n```\n\n#### Redis-Search Default Dialect\n\nIn 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.\n\n**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.\nFor example:\n```\n\tres2, err := rdb.FTSearchWithArgs(ctx,\n\t\t\"idx:bicycle\",\n\t\t\"@pickup_zone:[CONTAINS $bike]\",\n\t\t&redis.FTSearchOptions{\n\t\t\tParams: map[string]interface{}{\n\t\t\t\t\"bike\": \"POINT(-0.1278 51.5074)\",\n\t\t\t},\n\t\t\tDialectVersion: 3,\n\t\t},\n\t).Result()\n```\nYou can find further details in the [query dialect documentation](https:\u002F\u002Fredis.io\u002Fdocs\u002Flatest\u002Fdevelop\u002Finteract\u002Fsearch-and-query\u002Fadvanced-concepts\u002Fdialects\u002F).\n\n#### Custom buffer sizes\nPrior to v9.12, the buffer size was the default go value of 4096 bytes. Starting from v9.12, \ngo-redis uses 32KiB read and write buffers by default for optimal performance.\nFor high-throughput applications or large pipelines, you can customize buffer sizes:\n\n```go\nrdb := redis.NewClient(&redis.Options{\n    Addr:            \"localhost:6379\",\n    ReadBufferSize:  1024 * 1024, \u002F\u002F 1MiB read buffer\n    WriteBufferSize: 1024 * 1024, \u002F\u002F 1MiB write buffer\n})\n```\n\n**Important**: If you experience any issues with the default buffer sizes, please try setting them to the go default of 4096 bytes.\n\n## Contributing\nWe 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.\nWe appreciate your help in making go-redis better for everyone.\nIf 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.\n\n## Look and feel\n\nSome corner cases:\n\n```go\n\u002F\u002F SET key value EX 10 NX\nset, err := rdb.SetNX(ctx, \"key\", \"value\", 10*time.Second).Result()\n\n\u002F\u002F SET key value keepttl NX\nset, err := rdb.SetNX(ctx, \"key\", \"value\", redis.KeepTTL).Result()\n\n\u002F\u002F SORT list LIMIT 0 2 ASC\nvals, err := rdb.Sort(ctx, \"list\", &redis.Sort{Offset: 0, Count: 2, Order: \"ASC\"}).Result()\n\n\u002F\u002F ZRANGEBYSCORE zset -inf +inf WITHSCORES LIMIT 0 2\nvals, err := rdb.ZRangeByScoreWithScores(ctx, \"zset\", &redis.ZRangeBy{\n    Min: \"-inf\",\n    Max: \"+inf\",\n    Offset: 0,\n    Count: 2,\n}).Result()\n\n\u002F\u002F ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3 AGGREGATE SUM\nvals, err := rdb.ZInterStore(ctx, \"out\", &redis.ZStore{\n    Keys: []string{\"zset1\", \"zset2\"},\n    Weights: []int64{2, 3}\n}).Result()\n\n\u002F\u002F EVAL \"return {KEYS[1],ARGV[1]}\" 1 \"key\" \"hello\"\nvals, err := rdb.Eval(ctx, \"return {KEYS[1],ARGV[1]}\", []string{\"key\"}, \"hello\").Result()\n\n\u002F\u002F custom command\nres, err := rdb.Do(ctx, \"set\", \"key\", \"value\").Result()\n```\n\n## Typed Errors\n\ngo-redis provides typed error checking functions for common Redis errors:\n\n```go\n\u002F\u002F Cluster and replication errors\nredis.IsLoadingError(err)        \u002F\u002F Redis is loading the dataset\nredis.IsReadOnlyError(err)       \u002F\u002F Write to read-only replica\nredis.IsClusterDownError(err)    \u002F\u002F Cluster is down\nredis.IsTryAgainError(err)       \u002F\u002F Command should be retried\nredis.IsMasterDownError(err)     \u002F\u002F Master is down\nredis.IsMovedError(err)          \u002F\u002F Returns (address, true) if key moved\nredis.IsAskError(err)            \u002F\u002F Returns (address, true) if key being migrated\n\n\u002F\u002F Connection and resource errors\nredis.IsMaxClientsError(err)     \u002F\u002F Maximum clients reached\nredis.IsAuthError(err)           \u002F\u002F Authentication failed (NOAUTH, WRONGPASS, unauthenticated)\nredis.IsPermissionError(err)     \u002F\u002F Permission denied (NOPERM)\nredis.IsOOMError(err)            \u002F\u002F Out of memory (OOM)\n\n\u002F\u002F Transaction errors\nredis.IsExecAbortError(err)      \u002F\u002F Transaction aborted (EXECABORT)\n```\n\n### Error Wrapping in Hooks\n\nWhen wrapping errors in hooks, use custom error types with `Unwrap()` method (preferred) or `fmt.Errorf` with `%w`. Always call `cmd.SetErr()` to preserve error type information:\n\n```go\n\u002F\u002F Custom error type (preferred)\ntype AppError struct {\n    Code      string\n    RequestID string\n    Err       error\n}\n\nfunc (e *AppError) Error() string {\n    return fmt.Sprintf(\"[%s] request_id=%s: %v\", e.Code, e.RequestID, e.Err)\n}\n\nfunc (e *AppError) Unwrap() error {\n    return e.Err\n}\n\n\u002F\u002F Hook implementation\nfunc (h MyHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {\n    return func(ctx context.Context, cmd redis.Cmder) error {\n        err := next(ctx, cmd)\n        if err != nil {\n            \u002F\u002F Wrap with custom error type\n            wrappedErr := &AppError{\n                Code:      \"REDIS_ERROR\",\n                RequestID: getRequestID(ctx),\n                Err:       err,\n            }\n            cmd.SetErr(wrappedErr)\n            return wrappedErr  \u002F\u002F Return wrapped error to preserve it\n        }\n        return nil\n    }\n}\n\n\u002F\u002F Typed error detection works through wrappers\nif redis.IsLoadingError(err) {\n    \u002F\u002F Retry logic\n}\n\n\u002F\u002F Extract custom error if needed\nvar appErr *AppError\nif errors.As(err, &appErr) {\n    log.Printf(\"Request: %s\", appErr.RequestID)\n}\n```\n\nAlternatively, use `fmt.Errorf` with `%w`:\n```go\nwrappedErr := fmt.Errorf(\"context: %w\", err)\ncmd.SetErr(wrappedErr)\n```\n\n### Pipeline Hook Example\n\nFor pipeline operations, use `ProcessPipelineHook`:\n\n```go\ntype PipelineLoggingHook struct{}\n\nfunc (h PipelineLoggingHook) DialHook(next redis.DialHook) redis.DialHook {\n    return next\n}\n\nfunc (h PipelineLoggingHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {\n    return next\n}\n\nfunc (h PipelineLoggingHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook {\n    return func(ctx context.Context, cmds []redis.Cmder) error {\n        start := time.Now()\n\n        \u002F\u002F Execute the pipeline\n        err := next(ctx, cmds)\n\n        duration := time.Since(start)\n        log.Printf(\"Pipeline executed %d commands in %v\", len(cmds), duration)\n\n        \u002F\u002F Process individual command errors\n        \u002F\u002F Note: Individual command errors are already set on each cmd by the pipeline execution\n        for _, cmd := range cmds {\n            if cmdErr := cmd.Err(); cmdErr != nil {\n                \u002F\u002F Check for specific error types using typed error functions\n                if redis.IsAuthError(cmdErr) {\n                    log.Printf(\"Auth error in pipeline command %s: %v\", cmd.Name(), cmdErr)\n                } else if redis.IsPermissionError(cmdErr) {\n                    log.Printf(\"Permission error in pipeline command %s: %v\", cmd.Name(), cmdErr)\n                }\n\n                \u002F\u002F Optionally wrap individual command errors to add context\n                \u002F\u002F The wrapped error preserves type information through errors.As()\n                wrappedErr := fmt.Errorf(\"pipeline cmd %s failed: %w\", cmd.Name(), cmdErr)\n                cmd.SetErr(wrappedErr)\n            }\n        }\n\n        \u002F\u002F Return the pipeline-level error (connection errors, etc.)\n        \u002F\u002F You can wrap it if needed, or return it as-is\n        return err\n    }\n}\n\n\u002F\u002F Register the hook\nrdb.AddHook(PipelineLoggingHook{})\n\n\u002F\u002F Use pipeline - errors are still properly typed\npipe := rdb.Pipeline()\npipe.Set(ctx, \"key1\", \"value1\", 0)\npipe.Get(ctx, \"key2\")\n_, err := pipe.Exec(ctx)\n```\n\n## Run the test\n\nRecommended to use Docker, just need to run:\n```shell\nmake test\n```\n\n## See also\n\n- [Golang ORM](https:\u002F\u002Fbun.uptrace.dev) for PostgreSQL, MySQL, MSSQL, and SQLite\n- [Golang PostgreSQL](https:\u002F\u002Fbun.uptrace.dev\u002Fpostgres\u002F)\n- [Golang HTTP router](https:\u002F\u002Fbunrouter.uptrace.dev\u002F)\n- [Golang ClickHouse ORM](https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fgo-clickhouse)\n\n## Contributors\n\n> The go-redis project was originally initiated by :star: [**uptrace\u002Fuptrace**](https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fuptrace).\n> Uptrace is an open-source APM tool that supports distributed tracing, metrics, and logs. You can\n> use it to monitor applications and set up automatic alerts to receive notifications via email,\n> Slack, Telegram, and others.\n>\n> See [OpenTelemetry](https:\u002F\u002Fgithub.com\u002Fredis\u002Fgo-redis\u002Ftree\u002Fmaster\u002Fexample\u002Fotel) example which\n> demonstrates how you can use Uptrace to monitor go-redis.\n\nThanks to all the people who already contributed!\n\n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fredis\u002Fgo-redis\u002Fgraphs\u002Fcontributors\">\n  \u003Cimg src=\"https:\u002F\u002Fcontributors-img.web.app\u002Fimage?repo=redis\u002Fgo-redis\" \u002F>\n\u003C\u002Fa>\n","go-redis 是官方的 Go 语言 Redis 客户端库，它提供了一个简洁的接口来与 Redis 服务器进行交互。该项目支持最新三个版本的 Redis，并且兼容多种 Go 版本（包括 1.24 及以上），确保了广泛的适用性和稳定性。其核心功能包括对 Redis 集群的支持、丰富的命令集以及高效的连接池管理等。此外，go-redis 还提供了详细的文档和活跃的社区支持。适用于需要高性能缓存、消息队列或数据存储解决方案的 Go 应用开发场景中。",2,"2026-06-11 03:00:30","top_language"]