{"id":24108210,"url":"https://github.com/redis-developer/redisjson-for-gophers","last_synced_at":"2025-06-24T18:35:27.483Z","repository":{"id":271789674,"uuid":"914565610","full_name":"redis-developer/redisjson-for-gophers","owner":"redis-developer","description":"We all know Go is fast. Would you like to go even faster? Pair it with Redis and find out.","archived":false,"fork":false,"pushed_at":"2025-05-07T00:15:04.000Z","size":793,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-07T01:25:11.517Z","etag":null,"topics":["golang","redis","redis-cloud","redis-insight"],"latest_commit_sha":null,"homepage":"https://redis.io/docs/latest/get-started/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redis-developer.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-09T21:07:22.000Z","updated_at":"2025-05-07T00:15:08.000Z","dependencies_parsed_at":"2025-01-09T22:37:40.996Z","dependency_job_id":"37c56aae-acfe-4f66-9989-e27a5a2c742c","html_url":"https://github.com/redis-developer/redisjson-for-gophers","commit_stats":null,"previous_names":["redis-developer/redisjson-for-gophers"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/redis-developer/redisjson-for-gophers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredisjson-for-gophers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredisjson-for-gophers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredisjson-for-gophers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredisjson-for-gophers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redis-developer","download_url":"https://codeload.github.com/redis-developer/redisjson-for-gophers/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredisjson-for-gophers/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261734616,"owners_count":23201859,"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":["golang","redis","redis-cloud","redis-insight"],"created_at":"2025-01-10T23:26:26.248Z","updated_at":"2025-06-24T18:35:27.453Z","avatar_url":"https://github.com/redis-developer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redis JSON for Gophers\n\nThis project contains an example that showcases different features from the official [Go Client for Redis](https://github.com/redis/go-redis) that you can use as a reference about how to get started with the support for JSON in Redis in your Go apps. It is not intended to provide the full spectrum of what the client is capable of—but it certainly puts you on the right track.\n\nYou can run this code with an Redis instance running locally, to which you can leverage the [Docker Compose code](./docker-compose.yml) available in the project. Alternatively, you can also run this code with [Redis Cloud](https://redis.io/cloud/) that can be easily created using the [Terraform code](./redis-cloud.tf) also available in the project.\n\n## Examples available in this project:\n\n### 🟥 Movies Loading\n\nThe data model from this project is a collection of movies from the file [movies.json](./movies.json). This file will be [loaded](logic/movies.go) in memory and made available within the context, which the other functions will work with. Here is an example of a movie:\n\n```json\n{\n  \"title\": \"Blade\",\n  \"year\": 1998,\n  \"plot\": \"A half-vampire, half-mortal man becomes a protector of the mortal race, while slaying evil vampires.\",\n  \"runningTime\": 7200,\n  \"releaseDate\": \"1998-08-19T00:00:00Z\",\n  \"rating\": 7,\n  \"genres\": [\n    \"Action\",\n    \"Fantasy\",\n    \"Horror\"\n  ],\n  \"actors\": [\n    \"Wesley Snipes\",\n    \"Stephen Dorff\",\n    \"Kris Kristofferson\"\n  ],\n  \"directors\": [\n    \"Stephen Norrington\"\n  ]\n}\n```\n\n### 🟥 Connection Handling\n\nOnce the movies are loaded, the code will create a [connection](logic/connect.go) with Redis and make this connection available within the context as well.\n\n```go\nconnOpts, err := redis.ParseURL(redisConnectionURL)\nif err != nil {\n    panic(fmt.Errorf(\"failed to parse Redis URL: %w\", err))\n}\nredisClient := redis.NewClient(connOpts)\n\n_, err = redisClient.Ping(ctx).Result()\nif err != nil {\npanic(fmt.Errorf(\"error connecting with Redis: %w\", err))\n}\n\nreturn context.WithValue(ctx, domain.ClientKey, redisClient)\n```\n\n### 🟥 Document Indexing\n\nAll the movies will be [indexed](logic/index.go) in Redis. The example uses [Redis Pipelining](https://redis.io/docs/latest/develop/use/pipelining/) to index documents.\n\n```go\npipeline := redisClient.Pipeline()\nfor movieID, movie := range movies {\n    movieAsJSON, err := json.Marshal(movie)\n    if err != nil {\n        log.Printf(\"Error marshaling movie into JSON: %v\", err)\n    }\n    pipeline.JSONSet(ctx, KeyPrefix+strconv.Itoa(movieID+1), \"$\", string(movieAsJSON))\n}\n\n_, _ := pipeline.Exec(ctx)\n```\n\n### 🟥 Document Lookup\n\nAn example of [document lookup](logic/lookup.go) is also available. Out of all movies loaded, an key will be randomly selected, and the document associated with this key will be looked up. Just like you would do with:\n\n```bash\nJSON.GET movie:1234 $.title\n```\n\n### 🟥 Aggregation Analytics\n\nFinally, the project also runs a very interesting [aggregation](logic/aggreg.go) to find out the top five genres and their respective movie counts. Just like you would do with:\n\n```bash\nFT.AGGREGATE json_movies_index * GROUPBY 1 @genres REDUCE COUNT 0 AS Count SORTBY 2 @Count DESC MAX 5\n```\n\n### 🟥 Document Searches\n\nObviously, this project couldn't leave behind an example of a document search. The implemented [search](logic/search.go) to look for all the best action movies from [Keanu Reeves](https://en.wikipedia.org/wiki/Keanu_Reeves) from 1995 to 2005.\n\n```bash\nFT.SEARCH movies_index \"@actors:{Keanu Reeves} @genres:{action} @rating:[7.0 +inf] @year:[1995 2005]\" RETURN 3 $.title $.year $.rating\n```\n\n# License\n\nThis project is licensed under the [Apache 2.0 License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fredisjson-for-gophers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredis-developer%2Fredisjson-for-gophers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fredisjson-for-gophers/lists"}