{"id":13412394,"url":"https://github.com/redis/go-redis","last_synced_at":"2026-01-25T12:07:52.672Z","repository":{"id":4074183,"uuid":"5179099","full_name":"redis/go-redis","owner":"redis","description":"Redis Go client","archived":false,"fork":false,"pushed_at":"2026-01-24T19:16:08.000Z","size":28679,"stargazers_count":21856,"open_issues_count":64,"forks_count":2528,"subscribers_count":252,"default_branch":"master","last_synced_at":"2026-01-25T08:14:48.122Z","etag":null,"topics":["go","golang","redis","redis-client","redis-cluster"],"latest_commit_sha":null,"homepage":"https://redis.io","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"custom":["https://uptrace.dev/sponsor"]}},"created_at":"2012-07-25T13:01:39.000Z","updated_at":"2026-01-25T06:06:51.000Z","dependencies_parsed_at":"2026-01-17T20:10:08.524Z","dependency_job_id":null,"html_url":"https://github.com/redis/go-redis","commit_stats":{"total_commits":1791,"total_committers":336,"mean_commits":5.330357142857143,"dds":0.4310441094360692,"last_synced_commit":"91dddc2e1108c779e8c5b85fd667029873c95172"},"previous_names":["go-redis/redis","vmihailenco/redis"],"tags_count":478,"template":false,"template_full_name":null,"purl":"pkg:github/redis/go-redis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fgo-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fgo-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fgo-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fgo-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redis","download_url":"https://codeload.github.com/redis/go-redis/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis%2Fgo-redis/sbom","scorecard":{"id":432394,"data":{"date":"2025-08-11","repo":{"name":"github.com/redis/go-redis","commit":"97817108ddf27fe590f804ce0390d1d2b4a84ce9"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":7.2,"checks":[{"name":"Maintained","score":10,"reason":"30 commit(s) and 12 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":10,"reason":"all changesets reviewed","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":1,"reason":"dependency not pinned by hash detected -- score normalized to 1","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/build.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:35: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/build.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:87: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/build.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:96: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/build.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:53: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:67: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/doctests.yaml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/doctests.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/doctests.yaml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/doctests.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/golangci-lint.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/golangci-lint.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/golangci-lint.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/golangci-lint.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release-drafter.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/release-drafter.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/spellcheck.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/spellcheck.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/spellcheck.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/spellcheck.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/stale-issues.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/stale-issues.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/stale-issues.yml:67: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/stale-issues.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-redis-enterprise.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/test-redis-enterprise.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-redis-enterprise.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/test-redis-enterprise.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test-redis-enterprise.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/redis/go-redis/test-redis-enterprise.yml/master?enable=pin","Info:   0 out of  16 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   4 third-party GitHubAction dependencies pinned","Info:   1 out of   1 goCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:25","Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:26","Warn: jobLevel 'contents' permission set to 'write': .github/workflows/release-drafter.yml:14","Info: topLevel 'contents' permission set to 'read': .github/workflows/build.yml:10","Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1","Info: topLevel 'contents' permission set to 'read': .github/workflows/doctests.yaml:10","Info: topLevel 'contents' permission set to 'read': .github/workflows/golangci-lint.yml:15","Info: topLevel 'pull-requests' permission set to 'read': .github/workflows/golangci-lint.yml:16","Info: found token with 'none' permissions: .github/workflows/release-drafter.yml:1","Warn: no topLevel permission defined: .github/workflows/spellcheck.yml:1","Warn: no topLevel permission defined: .github/workflows/stale-issues.yml:1","Info: topLevel 'contents' permission set to 'read': .github/workflows/test-redis-enterprise.yml:9"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: BSD 2-Clause \"Simplified\" License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":10,"reason":"project is fuzzed","details":["Info: OSSFuzz integration found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"SAST","score":10,"reason":"SAST tool is run on all commits","details":["Info: SAST configuration detected: CodeQL","Info: all commits (30) are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":9,"reason":"1 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GO-2025-3595 / GHSA-vvgc-356p-c3xw"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T03:41:15.999Z","repository_id":4074183,"created_at":"2025-08-19T03:41:15.999Z","updated_at":"2025-08-19T03:41:15.999Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28752681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T10:25:12.305Z","status":"ssl_error","status_checked_at":"2026-01-25T10:25:11.933Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","redis","redis-client","redis-cluster"],"created_at":"2024-07-30T20:01:24.187Z","updated_at":"2026-01-25T12:07:52.666Z","avatar_url":"https://github.com/redis.png","language":"Go","readme":"# Redis client for Go\n\n[![build workflow](https://github.com/redis/go-redis/actions/workflows/build.yml/badge.svg)](https://github.com/redis/go-redis/actions)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/redis/go-redis/v9)](https://pkg.go.dev/github.com/redis/go-redis/v9?tab=doc)\n[![Documentation](https://img.shields.io/badge/redis-documentation-informational)](https://redis.io/docs/latest/develop/clients/go/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/redis/go-redis/v9)](https://goreportcard.com/report/github.com/redis/go-redis/v9)\n[![codecov](https://codecov.io/github/redis/go-redis/graph/badge.svg?token=tsrCZKuSSw)](https://codecov.io/github/redis/go-redis)\n\n[![Discord](https://img.shields.io/discord/697882427875393627.svg?style=social\u0026logo=discord)](https://discord.gg/W4txy5AeKM)\n[![Twitch](https://img.shields.io/twitch/status/redisinc?style=social)](https://www.twitch.tv/redisinc)\n[![YouTube](https://img.shields.io/youtube/channel/views/UCD78lHSwYqMlyetR0_P4Vig?style=social)](https://www.youtube.com/redisinc)\n[![Twitter](https://img.shields.io/twitter/follow/redisinc?style=social)](https://twitter.com/redisinc)\n[![Stack Exchange questions](https://img.shields.io/stackexchange/stackoverflow/t/go-redis?style=social\u0026logo=stackoverflow\u0026label=Stackoverflow)](https://stackoverflow.com/questions/tagged/go-redis)\n\n\u003e 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://raw.githubusercontent.com/redis/redis/8.0/00-RELEASENOTES) - using Redis CE 8.0\n- [Redis 8.2](https://raw.githubusercontent.com/redis/redis/8.2/00-RELEASENOTES) - using Redis CE 8.2 \n- [Redis 8.4](https://raw.githubusercontent.com/redis/redis/8.4/00-RELEASENOTES) - using Redis CE 8.4\n\nAlthough the `go.mod` states it requires at minimum `go 1.21`, our CI is configured to run the tests against all three\nversions of Redis and multiple versions of Go ([1.21](https://go.dev/doc/devel/release#go1.21.0),\n[1.23](https://go.dev/doc/devel/release#go1.23.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/v9`  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://university.redis.com/)\n\n[Build faster with the Redis Launchpad](https://launchpad.redis.com/)\n\n[Try the Redis Cloud](https://redis.com/try-free/)\n\n[Dive in developer tutorials](https://developer.redis.com/)\n\n[Join the Redis community](https://redis.com/community/)\n\n[Work at Redis](https://redis.com/company/careers/jobs/)\n\n\n## Resources\n\n- [Discussions](https://github.com/redis/go-redis/discussions)\n- [Chat](https://discord.gg/W4txy5AeKM)\n- [Reference](https://pkg.go.dev/github.com/redis/go-redis/v9)\n- [Examples](https://pkg.go.dev/github.com/redis/go-redis/v9#pkg-examples)\n\n## old documentation\n\n- [English](https://redis.uptrace.dev)\n- [简体中文](https://redis.uptrace.dev/zh/)\n\n## Ecosystem\n\n- [Entra ID (Azure AD)](https://github.com/redis/go-redis-entraid)\n- [Distributed Locks](https://github.com/bsm/redislock)\n- [Redis Cache](https://github.com/go-redis/cache)\n- [Rate limiting](https://github.com/go-redis/redis_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/Sub](https://redis.uptrace.dev/guide/go-redis-pubsub.html).\n- [Pipelines and transactions](https://redis.uptrace.dev/guide/go-redis-pipelines.html).\n- [Scripting](https://redis.uptrace.dev/guide/lua-scripting.html).\n- [Redis Sentinel](https://redis.uptrace.dev/guide/go-redis-sentinel.html).\n- [Redis Cluster](https://redis.uptrace.dev/guide/go-redis-cluster.html).\n- [Redis Performance Monitoring](https://redis.uptrace.dev/guide/redis-performance-monitoring.html).\n- [Redis Probabilistic [RedisStack]](https://redis.io/docs/data-types/probabilistic/)\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://github.com/golang/go/wiki/Modules) support. So make sure to initialize a Go\nmodule:\n\n```shell\ngo mod init github.com/my/repo\n```\n\nThen install go-redis/**v9**:\n\n```shell\ngo get github.com/redis/go-redis/v9\n```\n\n## Quickstart\n\n```go\nimport (\n    \"context\"\n    \"fmt\"\n\n    \"github.com/redis/go-redis/v9\"\n)\n\nvar ctx = context.Background()\n\nfunc ExampleClient() {\n    rdb := redis.NewClient(\u0026redis.Options{\n        Addr:     \"localhost:6379\",\n        Password: \"\", // no password set\n        DB:       0,  // 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    // Output: key value\n    // key2 does not exist\n}\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)  // Called when credentials are updated\n    OnError(err error)              // 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(\u0026redis.Options{\n    Addr: \"localhost:6379\",\n    StreamingCredentialsProvider: \u0026MyCredentialsProvider{},\n})\n```\n\n**Note:** The streaming credentials provider can be used with [go-redis-entraid](https://github.com/redis/go-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/redis/go-redis/v9\"\n    \"github.com/redis/go-redis-entraid\"\n)\n\n// Create an Entra ID credentials provider\nprovider := entraid.NewDefaultAzureIdentityProvider()\n\n// Configure Redis client with Entra ID authentication\nrdb := redis.NewClient(\u0026redis.Options{\n    Addr: \"your-redis-server.redis.cache.windows.net:6380\",\n    StreamingCredentialsProvider: provider,\n    TLSConfig: \u0026tls.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(\u0026redis.Options{\n    Addr: \"localhost:6379\",\n    CredentialsProviderContext: func(ctx context.Context) (string, string, error) {\n        // 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(\u0026redis.Options{\n    Addr: \"localhost:6379\",\n    CredentialsProvider: func() (string, string) {\n        // Return username and password\n        return \"user\", \"pass\"\n    },\n})\n```\n\n#### 4. Username/Password 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(\u0026redis.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/Password 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(\u0026redis.Options{\n    Addr:     \"localhost:6379\",\n    Password: \"\", // no password set\n    DB:       0,  // use default DB\n    Protocol: 3,  // 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://github.com/redis/redis-specifications/tree/master/uri/redis.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/redis/go-redis/v9\"\n)\n\nfunc ExampleClient() *redis.Client {\n    url := \"redis://user:password@localhost:6379/0?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/redis/go-redis/v9\"\n    \"github.com/redis/go-redis/extra/redisotel/v9\"\n    \"errors\"\n)\n\nfunc main() {\n    ...\n    rdb := redis.NewClient(\u0026redis.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(\u0026redis.Options{\n    Addr:            \"localhost:6379\",\n    ReadBufferSize:  1024 * 1024, // 1MiB read buffer\n    WriteBufferSize: 1024 * 1024, // 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(\u0026redis.Options{\n    Addr:            \"localhost:6379\",\n    Password:        \"\",\n    DB:              0,\n    DisableIdentity: true, // 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(\u0026redis.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\", \u0026redis.FTSearchOptions{}).RawResult()\nval1 := client.FTSearchWithArgs(ctx, \"txt\", \"foo bar\", \u0026redis.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\u0026redis.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://redis.io/docs/latest/develop/interact/search-and-query/advanced-concepts/dialects/).\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(\u0026redis.Options{\n    Addr:            \"localhost:6379\",\n    ReadBufferSize:  1024 * 1024, // 1MiB read buffer\n    WriteBufferSize: 1024 * 1024, // 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// SET key value EX 10 NX\nset, err := rdb.SetNX(ctx, \"key\", \"value\", 10*time.Second).Result()\n\n// SET key value keepttl NX\nset, err := rdb.SetNX(ctx, \"key\", \"value\", redis.KeepTTL).Result()\n\n// SORT list LIMIT 0 2 ASC\nvals, err := rdb.Sort(ctx, \"list\", \u0026redis.Sort{Offset: 0, Count: 2, Order: \"ASC\"}).Result()\n\n// ZRANGEBYSCORE zset -inf +inf WITHSCORES LIMIT 0 2\nvals, err := rdb.ZRangeByScoreWithScores(ctx, \"zset\", \u0026redis.ZRangeBy{\n    Min: \"-inf\",\n    Max: \"+inf\",\n    Offset: 0,\n    Count: 2,\n}).Result()\n\n// ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3 AGGREGATE SUM\nvals, err := rdb.ZInterStore(ctx, \"out\", \u0026redis.ZStore{\n    Keys: []string{\"zset1\", \"zset2\"},\n    Weights: []int64{2, 3}\n}).Result()\n\n// 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// 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// Cluster and replication errors\nredis.IsLoadingError(err)        // Redis is loading the dataset\nredis.IsReadOnlyError(err)       // Write to read-only replica\nredis.IsClusterDownError(err)    // Cluster is down\nredis.IsTryAgainError(err)       // Command should be retried\nredis.IsMasterDownError(err)     // Master is down\nredis.IsMovedError(err)          // Returns (address, true) if key moved\nredis.IsAskError(err)            // Returns (address, true) if key being migrated\n\n// Connection and resource errors\nredis.IsMaxClientsError(err)     // Maximum clients reached\nredis.IsAuthError(err)           // Authentication failed (NOAUTH, WRONGPASS, unauthenticated)\nredis.IsPermissionError(err)     // Permission denied (NOPERM)\nredis.IsOOMError(err)            // Out of memory (OOM)\n\n// Transaction errors\nredis.IsExecAbortError(err)      // 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// 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// 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            // Wrap with custom error type\n            wrappedErr := \u0026AppError{\n                Code:      \"REDIS_ERROR\",\n                RequestID: getRequestID(ctx),\n                Err:       err,\n            }\n            cmd.SetErr(wrappedErr)\n            return wrappedErr  // Return wrapped error to preserve it\n        }\n        return nil\n    }\n}\n\n// Typed error detection works through wrappers\nif redis.IsLoadingError(err) {\n    // Retry logic\n}\n\n// Extract custom error if needed\nvar appErr *AppError\nif errors.As(err, \u0026appErr) {\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        // 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        // Process individual command errors\n        // 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                // 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                // Optionally wrap individual command errors to add context\n                // 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        // Return the pipeline-level error (connection errors, etc.)\n        // You can wrap it if needed, or return it as-is\n        return err\n    }\n}\n\n// Register the hook\nrdb.AddHook(PipelineLoggingHook{})\n\n// 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://bun.uptrace.dev) for PostgreSQL, MySQL, MSSQL, and SQLite\n- [Golang PostgreSQL](https://bun.uptrace.dev/postgres/)\n- [Golang HTTP router](https://bunrouter.uptrace.dev/)\n- [Golang ClickHouse ORM](https://github.com/uptrace/go-clickhouse)\n\n## Contributors\n\n\u003e The go-redis project was originally initiated by :star: [**uptrace/uptrace**](https://github.com/uptrace/uptrace).\n\u003e Uptrace is an open-source APM tool that supports distributed tracing, metrics, and logs. You can\n\u003e use it to monitor applications and set up automatic alerts to receive notifications via email,\n\u003e Slack, Telegram, and others.\n\u003e\n\u003e See [OpenTelemetry](https://github.com/redis/go-redis/tree/master/example/otel) example which\n\u003e demonstrates how you can use Uptrace to monitor go-redis.\n\nThanks to all the people who already contributed!\n\n\u003ca href=\"https://github.com/redis/go-redis/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contributors-img.web.app/image?repo=redis/go-redis\" /\u003e\n\u003c/a\u003e\n","funding_links":["https://uptrace.dev/sponsor"],"categories":["Popular","Go","开源类库","Middleware","Clients","其他__大数据","Database Drivers","golang","数据库驱动程序","Data Integration Frameworks","Repositories","\u003ca name=\"Go\"\u003e\u003c/a\u003eGo"],"sub_categories":["数据库","Go","网络服务_其他","NoSQL Database Drivers","NoSQL数据库驱动程序"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis%2Fgo-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredis%2Fgo-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis%2Fgo-redis/lists"}