{"id":20294178,"url":"https://github.com/grab/go-redis","last_synced_at":"2026-02-26T01:03:27.737Z","repository":{"id":215869056,"uuid":"736570211","full_name":"grab/go-redis","owner":"grab","description":"go-redis","archived":false,"fork":false,"pushed_at":"2024-11-25T10:17:28.000Z","size":5026,"stargazers_count":1,"open_issues_count":6,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-25T10:41:34.029Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":false,"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/grab.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://uptrace.dev/sponsor"]}},"created_at":"2023-12-28T09:06:14.000Z","updated_at":"2024-01-05T04:15:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"1d872299-9e6b-4831-b04a-60fe223a0329","html_url":"https://github.com/grab/go-redis","commit_stats":null,"previous_names":["grab/go-redis"],"tags_count":273,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grab%2Fgo-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grab%2Fgo-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grab%2Fgo-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grab%2Fgo-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grab","download_url":"https://codeload.github.com/grab/go-redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233870307,"owners_count":18743364,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-14T15:28:08.562Z","updated_at":"2026-02-26T01:03:27.695Z","avatar_url":"https://github.com/grab.png","language":"Go","funding_links":["https://uptrace.dev/sponsor"],"categories":[],"sub_categories":[],"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.uptrace.dev/)\n[![Chat](https://discordapp.com/api/guilds/752070105847955518/widget.png)](https://discord.gg/rWtp5Aj)\n\n\u003e go-redis is brought to you 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](example/otel) example which demonstrates how you can use Uptrace to monitor\n\u003e go-redis.\n\n## Documentation\n\n- [English](https://redis.uptrace.dev)\n- [简体中文](https://redis.uptrace.dev/zh/)\n\n## Resources\n\n- [Discussions](https://github.com/redis/go-redis/discussions)\n- [Chat](https://discord.gg/rWtp5Aj)\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## Ecosystem\n\n- [Redis Mock](https://github.com/go-redis/redismock)\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\nThis client also works with [Kvrocks](https://github.com/apache/incubator-kvrocks), a distributed\nkey value NoSQL database that uses RocksDB as storage engine and is compatible with Redis protocol.\n\n## Features\n\n- Redis 3 commands except QUIT, MONITOR, and SYNC.\n- Automatic connection pooling with\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 Ring](https://redis.uptrace.dev/guide/ring.html).\n- [Redis Performance Monitoring](https://redis.uptrace.dev/guide/redis-performance-monitoring.html).\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    \"github.com/redis/go-redis/v9\"\n    \"fmt\"\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\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## 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## Run the test\n\ngo-redis will start a redis-server and run the test cases.\n\nThe paths of redis-server bin file and redis config file are defined in `main_test.go`:\n\n```go\nvar (\n\tredisServerBin, _  = filepath.Abs(filepath.Join(\"testdata\", \"redis\", \"src\", \"redis-server\"))\n\tredisServerConf, _ = filepath.Abs(filepath.Join(\"testdata\", \"redis\", \"redis.conf\"))\n)\n```\n\nFor local testing, you can change the variables to refer to your local files, or create a soft link\nto the corresponding folder for redis-server and copy the config file to `testdata/redis/`:\n\n```shell\nln -s /usr/bin/redis-server ./go-redis/testdata/redis/src\ncp ./go-redis/testdata/redis.conf ./go-redis/testdata/redis/\n```\n\nLastly, run:\n\n```shell\ngo test\n```\n\nAnother option is to run your specific tests with an already running redis. The example below, tests against a redis running on port 9999.:\n\n```shell\nREDIS_PORT=9999 go test \u003cyour options\u003e\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\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrab%2Fgo-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrab%2Fgo-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrab%2Fgo-redis/lists"}