{"id":13412402,"url":"https://github.com/shomali11/xredis","last_synced_at":"2025-05-12T21:22:15.671Z","repository":{"id":57494418,"uuid":"94270152","full_name":"shomali11/xredis","owner":"shomali11","description":"Go Redis Client","archived":false,"fork":false,"pushed_at":"2019-06-08T14:36:42.000Z","size":157,"stargazers_count":19,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-20T18:38:35.769Z","etag":null,"topics":["connection-pool","easy","easy-to-use","go","golang","options","redigo","redis","redis-cache","redis-client","redis-sentinel","sentinel","typesafe"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shomali11.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-14T00:19:26.000Z","updated_at":"2022-09-26T09:47:39.000Z","dependencies_parsed_at":"2022-09-03T02:10:45.147Z","dependency_job_id":null,"html_url":"https://github.com/shomali11/xredis","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shomali11%2Fxredis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shomali11%2Fxredis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shomali11%2Fxredis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shomali11%2Fxredis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shomali11","download_url":"https://codeload.github.com/shomali11/xredis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253823718,"owners_count":21969898,"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":["connection-pool","easy","easy-to-use","go","golang","options","redigo","redis","redis-cache","redis-client","redis-sentinel","sentinel","typesafe"],"created_at":"2024-07-30T20:01:24.265Z","updated_at":"2025-05-12T21:22:15.651Z","avatar_url":"https://github.com/shomali11.png","language":"Go","funding_links":[],"categories":["Database Drivers","\u003cspan id=\"数据库驱动-database-drivers\"\u003e数据库驱动 Database Drivers\u003c/span\u003e","数据库驱动程序","Data Integration Frameworks","数据库驱动","数据库驱动`连接和操作数据库工具`","NoSQL Databases","Generators","數據庫驅動"],"sub_categories":["NoSQL Database Drivers","Advanced Console UIs","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","NoSQL数据库驱动程序","高级控制台界面","SQL 查询语句构建库","高級控制台界面"],"readme":"# xredis [![Build Status](https://travis-ci.com/shomali11/xredis.svg?branch=master)](https://travis-ci.com/shomali11/xredis) [![Go Report Card](https://goreportcard.com/badge/github.com/shomali11/xredis)](https://goreportcard.com/report/github.com/shomali11/xredis) [![GoDoc](https://godoc.org/github.com/shomali11/xredis?status.svg)](https://godoc.org/github.com/shomali11/xredis) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nBuilt on top of [github.com/garyburd/redigo](https://github.com/garyburd/redigo) with the idea to simplify creating a Redis client, provide type safe calls and encapsulate the low level details to easily integrate with Redis.\n\n## Features\n\n* Type safe client\n* Easy to setup using\n    * Default client\n    * Custom client via set options\n    * `redigo`'s `redis.Pool`\n* Connection pool provided automatically\n* Support for Redis Sentinel\n    * Writes go to the Master\n    * Reads go to the Slaves. Falls back on Master if none are available.\n* Supports the following Redis commands\n    * **ECHO**, **INFO**, **PING**, **FLUSH**, **FLUSHALL**, **EXPIRE**, **APPEND**\n    * **SET**, **SETEX**, **SETNX**, **GET**, **DEL**, **EXISTS**, **KEYS**, **SCAN**, **GETRANGE**, **SETRANGE**\n    * **HSET**, **HGET**, **HGETALL**, **HDEL**, **HEXISTS**, **HKEYS**, **HSCAN**\n    * **INCR**, **INCRBY**, **INCRBYFLOAT**, **DECR**, **DECRBY**, **DECRBYFLOAT**\n    * **HINCR**, **HINCRBY**, **HINCRBYFLOAT**, **HDECR**, **HDECRBY**, **HDECRBYFLOAT**\n    * _More coming soon_\n* Full access to Redigo's API [github.com/garyburd/redigo](https://github.com/garyburd/redigo)\n\n## Dependencies\n\n* `redigo` [github.com/garyburd/redigo](https://github.com/garyburd/redigo)\n* `go-sentinel` [github.com/FZambia/go-sentinel](https://github.com/FZambia/go-sentinel)\n\n# Examples\n\n## Example 1\n\nUsing `DefaultClient` to create a redis client with default options\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/xredis\"\n)\n\nfunc main() {\n\tclient := xredis.DefaultClient()\n\tdefer client.Close()\n\n\tfmt.Println(client.Ping()) // PONG \u003cnil\u003e\n}\n```\n\nList of default options\n\n```text\ndefaultHost                  = \"localhost\"\ndefaultPort                  = 6379\ndefaultPassword              = \"\"\ndefaultDatabase              = 0\ndefaultNetwork               = \"tcp\"\ndefaultConnectTimeout        = time.Second\ndefaultWriteTimeout          = time.Second\ndefaultReadTimeout           = time.Second\ndefaultConnectionIdleTimeout = 240 * time.Second\ndefaultConnectionMaxIdle     = 100\ndefaultConnectionMaxActive   = 10000\ndefaultConnectionWait        = false\ndefaultTlsConfig             = nil\ndefaultTlsSkipVerify         = false\ndefaultTestOnBorrowTimeout   = time.Minute\n```\n\n## Example 2\n\nUsing `SetupClient` to create a redis client using provided options\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/xredis\"\n)\n\nfunc main() {\n\toptions := \u0026xredis.Options{\n\t\tHost: \"localhost\",\n\t\tPort: 6379,\n\t}\n\n\tclient := xredis.SetupClient(options)\n\tdefer client.Close()\n\n\tfmt.Println(client.Ping()) // PONG \u003cnil\u003e\n}\n```\n\nAvailable options to set\n\n```go\ntype Options struct {\n\tHost                  string\n\tPort                  int\n\tPassword              string\n\tDatabase              int\n\tNetwork               string\n\tConnectTimeout        time.Duration\n\tWriteTimeout          time.Duration\n\tReadTimeout           time.Duration\n\tConnectionIdleTimeout time.Duration\n\tConnectionMaxIdle     int\n\tConnectionMaxActive   int\n\tConnectionWait        bool\n\tTlsConfig             *tls.Config\n\tTlsSkipVerify         bool\n\tTestOnBorrowPeriod    time.Duration\n}\n```\n\n## Example 3\n\nUsing `SetupSentinelClient` to create a redis sentinel client using provided options\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/xredis\"\n)\n\nfunc main() {\n\toptions := \u0026xredis.SentinelOptions{\n\t\tAddresses:  []string{\"localhost:26379\"},\n\t\tMasterName: \"master\",\n\t}\n\n\tclient := xredis.SetupSentinelClient(options)\n\tdefer client.Close()\n\n\tfmt.Println(client.Ping()) // PONG \u003cnil\u003e\n}\n```\n\nAvailable options to set\n\n```go\ntype SentinelOptions struct {\n\tAddresses             []string\n\tMasterName            string\n\tPassword              string\n\tDatabase              int\n\tNetwork               string\n\tConnectTimeout        time.Duration\n\tWriteTimeout          time.Duration\n\tReadTimeout           time.Duration\n\tConnectionIdleTimeout time.Duration\n\tConnectionMaxIdle     int\n\tConnectionMaxActive   int\n\tConnectionWait        bool\n\tTlsConfig             *tls.Config\n\tTlsSkipVerify         bool\n}\n```\n\n## Example 4\n\nUsing `NewClient` to create a redis client using `redigo`'s `redis.Pool`\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/garyburd/redigo/redis\"\n\t\"github.com/shomali11/xredis\"\n)\n\nfunc main() {\n\tpool := \u0026redis.Pool{\n\t\tDial: func() (redis.Conn, error) {\n\t\t\treturn redis.Dial(\"tcp\", \"localhost:6379\")\n\t\t},\n\t}\n\n\tclient := xredis.NewClient(pool)\n\tdefer client.Close()\n\n\tfmt.Println(client.Ping()) // PONG \u003cnil\u003e\n}\n```\n\n## Example 5\n\nUsing the `Ping`, `Echo` \u0026 `Info` commands to ping, echo messages and return redis' information and statistics\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/xredis\"\n)\n\nfunc main() {\n\tclient := xredis.DefaultClient()\n\tdefer client.Close()\n\n\tfmt.Println(client.Ping())         // PONG \u003cnil\u003e\n\tfmt.Println(client.Echo(\"Hello\"))  // Hello \u003cnil\u003e\n\tfmt.Println(client.FlushDb())      // \u003cnil\u003e\n\tfmt.Println(client.FlushAll())     // \u003cnil\u003e\n\tfmt.Println(client.Info())         \n}\n```\n\n## Example 6\n\nUsing the `Set`, `Keys`, `Get`, `Exists`, `Expire`, `Append`, `GetRange`, `SetRange` and `Del` commands to show how to set, get and delete keys and values.\n_Note that the `Get` returns 3 values, a `string` result, a `bool` that determines whether the key exists and an `error`_\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/xredis\"\n)\n\nfunc main() {\n\tclient := xredis.DefaultClient()\n\tdefer client.Close()\n\n\tfmt.Println(client.Set(\"name\", \"Raed Shomali\")) // true \u003cnil\u003e\n\tfmt.Println(client.SetNx(\"name\", \"Hello\"))      // false \u003cnil\u003e\n\tfmt.Println(client.SetEx(\"id\", \"10\", 1))        // true \u003cnil\u003e\n\tfmt.Println(client.Expire(\"name\", 1))           // true \u003cnil\u003e\n\tfmt.Println(client.Expire(\"unknown\", 1))        // false \u003cnil\u003e\n\tfmt.Println(client.Keys(\"*\"))                   // [id name] \u003cnil\u003e\n\tfmt.Println(client.Get(\"name\"))                 // \"Raed Shomali\" true \u003cnil\u003e\n\tfmt.Println(client.Exists(\"name\"))              // true \u003cnil\u003e\n\tfmt.Println(client.Del(\"name\"))                 // 1 \u003cnil\u003e\n\tfmt.Println(client.Exists(\"name\"))              // false \u003cnil\u003e\n\tfmt.Println(client.Get(\"name\"))                 // \"\" false \u003cnil\u003e\n\tfmt.Println(client.Del(\"name\"))                 // 0 \u003cnil\u003e\n\tfmt.Println(client.Append(\"name\", \"a\"))         // 1 \u003cnil\u003e\n\tfmt.Println(client.Append(\"name\", \"b\"))         // 2 \u003cnil\u003e\n\tfmt.Println(client.Append(\"name\", \"c\"))         // 3 \u003cnil\u003e\n\tfmt.Println(client.Get(\"name\"))                 // \"abc\" true \u003cnil\u003e\n\tfmt.Println(client.GetRange(\"name\", 0 , 1))     // \"ab\" \u003cnil\u003e\n\tfmt.Println(client.SetRange(\"name\", 2, \"xyz\"))  // 5 \u003cnil\u003e\n\tfmt.Println(client.Get(\"name\"))                 // \"abxyz\" \u003cnil\u003e\n\tfmt.Println(client.Scan(0, \"*\"))                // 0 [name id] \u003cnil\u003e\n\tfmt.Println(client.Del(\"id\", \"name\"))           // 2 \u003cnil\u003e\n}\n```\n\n## Example 7\n\nUsing the `Incr`, `IncrBy`, `IncrByFloat`, `Decr`, `DecrBy`, `DecrByFloat` commands, we can increment and decrement a key's value\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/xredis\"\n)\n\nfunc main() {\n\tclient := xredis.DefaultClient()\n\tdefer client.Close()\n\n\tfmt.Println(client.Set(\"integer\", \"10\"))       // true \u003cnil\u003e\n\tfmt.Println(client.Set(\"float\", \"5.5\"))        // true \u003cnil\u003e\n\n\tfmt.Println(client.Get(\"integer\"))             // 10 true \u003cnil\u003e\n\tfmt.Println(client.Get(\"float\"))               // 5.5 true \u003cnil\u003e\n\n\tfmt.Println(client.Incr(\"integer\"))            // 11 \u003cnil\u003e\n\tfmt.Println(client.IncrBy(\"integer\", 10))      // 21 \u003cnil\u003e\n\tfmt.Println(client.DecrBy(\"integer\", 5))       // 16 \u003cnil\u003e\n\tfmt.Println(client.Decr(\"integer\"))            // 15 \u003cnil\u003e\n\n\tfmt.Println(client.IncrByFloat(\"float\", 3.3))  // 8.8 \u003cnil\u003e\n\tfmt.Println(client.DecrByFloat(\"float\", 1.1))  // 7.7 \u003cnil\u003e\n\n\tfmt.Println(client.Get(\"integer\"))             // 15 true \u003cnil\u003e\n\tfmt.Println(client.Get(\"float\"))               // 7.7 true \u003cnil\u003e\n\n\tfmt.Println(client.Del(\"integer\", \"float\"))    // 2 \u003cnil\u003e\n}\n```\n\n## Example 8\n\nUsing the `HSet`, `HKeys`, `HGet`, `HGetAll`, `HExists` and `HDel` commands to show how to set, get and delete hash keys, fields and values.\n_Note that the `HGetAll` returns 2 values, a `map[string]string` result and an `error`_\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/xredis\"\n)\n\nfunc main() {\n\tclient := xredis.DefaultClient()\n\tdefer client.Close()\n\n\tfmt.Println(client.HSet(\"hash\", \"name\", \"Raed Shomali\")) // true \u003cnil\u003e\n\tfmt.Println(client.HSet(\"hash\", \"sport\", \"Football\"))    // true \u003cnil\u003e\n\tfmt.Println(client.HKeys(\"hash\"))                        // [name sport] \u003cnil\u003e\n\tfmt.Println(client.HScan(\"hash\", 0, \"*\"))                // 0 [name Raed Shomali sport Football] \u003cnil\u003e\n\tfmt.Println(client.HGet(\"hash\", \"name\"))                 // \"Raed Shomali\" true \u003cnil\u003e\n\tfmt.Println(client.HGetAll(\"hash\"))                      // map[name:Raed Shomali sport:Football] \u003cnil\u003e\n\tfmt.Println(client.HExists(\"hash\", \"name\"))              // true \u003cnil\u003e\n\tfmt.Println(client.HDel(\"hash\", \"name\", \"sport\"))        // 2 \u003cnil\u003e\n\tfmt.Println(client.HGet(\"hash\", \"name\"))                 // \"\" false \u003cnil\u003e\n\tfmt.Println(client.HExists(\"hash\", \"name\"))              // false \u003cnil\u003e\n\tfmt.Println(client.HGetAll(\"hash\"))                      // map[] nil\n\tfmt.Println(client.HDel(\"hash\", \"name\"))                 // 0 \u003cnil\u003e\n\tfmt.Println(client.HKeys(\"hash\"))                        // [] \u003cnil\u003e\n}\n```\n\n## Example 9\n\nUsing the `HIncr`, `HIncrBy`, `HIncrByFloat`,`HDecr`, `HDecrBy` and `HDecrByFloat` commands to show how to increment and decrement hash fields' values.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/shomali11/xredis\"\n)\n\nfunc main() {\n\tclient := xredis.DefaultClient()\n\tdefer client.Close()\n\n\tfmt.Println(client.HSet(\"hash\", \"integer\", \"10\"))       // true \u003cnil\u003e\n\tfmt.Println(client.HSet(\"hash\", \"float\", \"5.5\"))        // true \u003cnil\u003e\n\n\tfmt.Println(client.HIncr(\"hash\", \"integer\"))            // 11 \u003cnil\u003e\n\tfmt.Println(client.HIncrBy(\"hash\", \"integer\", 10))      // 21 \u003cnil\u003e\n\tfmt.Println(client.HDecrBy(\"hash\", \"integer\", 5))       // 16 \u003cnil\u003e\n\tfmt.Println(client.HDecr(\"hash\", \"integer\"))            // 15 \u003cnil\u003e\n\n\tfmt.Println(client.HIncrByFloat(\"hash\", \"float\", 3.3))  // 8.8 \u003cnil\u003e\n\tfmt.Println(client.HDecrByFloat(\"hash\", \"float\", 1.1))  // 7.7 \u003cnil\u003e\n\n\tfmt.Println(client.HDel(\"hash\", \"integer\", \"float\"))    // 2 \u003cnil\u003e\n}\n```\n\n## Example 10\n\nCan't find the command you want? You have full access to `redigo`'s API.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/garyburd/redigo/redis\"\n\t\"github.com/shomali11/xredis\"\n)\n\nfunc main() {\n\tclient := xredis.DefaultClient()\n\tdefer client.Close()\n\n\tconnection := client.GetConnection()\n\tdefer connection.Close()\n\n\tfmt.Println(redis.String(connection.Do(\"INFO\")))\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshomali11%2Fxredis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshomali11%2Fxredis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshomali11%2Fxredis/lists"}