{"id":21672436,"url":"https://github.com/redis-developer/basic-redis-leaderboard-demo-go","last_synced_at":"2025-04-12T03:53:03.001Z","repository":{"id":45323276,"uuid":"337754587","full_name":"redis-developer/basic-redis-leaderboard-demo-go","owner":"redis-developer","description":"A basic Redis leaderboard demo app written in Go","archived":false,"fork":false,"pushed_at":"2023-08-15T16:52:59.000Z","size":5326,"stargazers_count":12,"open_issues_count":3,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-12T03:52:55.233Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/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}},"created_at":"2021-02-10T14:46:57.000Z","updated_at":"2024-11-29T13:18:17.000Z","dependencies_parsed_at":"2024-06-19T05:17:44.555Z","dependency_job_id":"659dcdba-0f8a-4e64-a023-980529bb0327","html_url":"https://github.com/redis-developer/basic-redis-leaderboard-demo-go","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/redis-developer%2Fbasic-redis-leaderboard-demo-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fbasic-redis-leaderboard-demo-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fbasic-redis-leaderboard-demo-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fbasic-redis-leaderboard-demo-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redis-developer","download_url":"https://codeload.github.com/redis-developer/basic-redis-leaderboard-demo-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514209,"owners_count":21116899,"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-25T13:29:15.609Z","updated_at":"2025-04-12T03:53:02.969Z","avatar_url":"https://github.com/redis-developer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Basic Redis Leaderboard Demo Golang\n\nShow how the Redis works with Golang.\n\n\n# How it works?\n\n![https://raw.githubusercontent.com/redis-developer](https://raw.githubusercontent.com/redis-developer/basic-redis-leaderboard-demo-go/master/image5.jpg?v=2\u0026s=2) \n\n## How the data is stored:\n\n- The AAPL's details - market cap of 2,6 triillions and USA origin - are stored in a hash like below:\n  - E.g `HSET \"company:AAPL\" symbol \"AAPL\" market_cap \"2600000000000\" country USA`\n- The Ranks of AAPL of 2,6 trillions are stored in a \u003ca href=\"https://redislabs.com/ebook/part-1-getting-started/chapter-1-getting-to-know-redis/1-2-what-redis-data-structures-look-like/1-2-5-sorted-sets-in-redis/\"\u003eZSET\u003c/a\u003e.\n  - E.g `ZADD companyLeaderboard 2600000000000 company:AAPL`\n\n## How the data is accessed:\n\n- Top 10 companies:\n  - E.g `ZREVRANGE companyLeaderboard 0 9 WITHSCORES`\n- All companies:\n  - E.g `ZREVRANGE companyLeaderboard 0 -1 WITHSCORES`\n- Bottom 10 companies:\n  - E.g `ZRANGE companyLeaderboard 0 9 WITHSCORES`\n- Between rank 10 and 15:\n  - E.g `ZREVRANGE companyLeaderboard 9 14 WITHSCORES`\n- Show ranks of AAPL, FB and TSLA:\n  - E.g `ZSCORE companyLeaderBoard company:AAPL company:FB company:TSLA`\n- Adding market cap to companies:\n  - E.g `ZINCRBY companyLeaderBoard 1000000000 \"company:FB\"`\n- Reducing market cap to companies:\n  - E.g `ZINCRBY companyLeaderBoard -1000000000 \"company:FB\"`\n- Companies over a Trillion:\n  - E.g `ZCOUNT companyLeaderBoard 1000000000000 +inf`\n- Companies between 500 billion and 1 trillion:\n  - E.g `ZCOUNT companyLeaderBoard 500000000000 1000000000000`\n\n### Code Example: Get top 10 companies\n\n```Go\nfunc (c Controller) Top10() ([]*Company, error) {\n    companies, err := c.r.ZRevRange(keyLeaderBoard, 0, 9)\n    if err != nil {\n        return nil, err\n    }\n    c.buildCompanies(companies)\n    c.buildRanks(companies)\n    return companies, nil\n}\n```\n\n## How to run it locally?\n\n#### Copy `.env.example` to create `.env`. And provide the values for environment variables if needed\n\n- REDIS_HOST: Redis server host\n- REDIS_PORT: Redis server port\n- REDIS_PASSWORD: Password to the server\n\n### Configure by an environment variable with Redis connection string URL\n\nIt is possible to pass any valid Redis URL for Redis options as in [ParseURL Example](https://pkg.go.dev/github.com/go-redis/redis?utm_source=gopls#example-ParseURL)\nThis way REDIS_HOST, REDIS_PORT, REDIS_PASSWORD are not needed.\n\n- REDIS_URL=redis :// [[username :] password@] host [:port][/database]\n- Example REDIS_URL=\"redis://p%40ssw0rd@redis-16379.hosted.com:16379/0\" from [redis-cli, the Redis command line interface](https://redis.io/topics/rediscli)\n\n        Scheme syntax:\n          Example: redis://user:secret@localhost:6379/0?foo=bar\u0026qux=baz\n\n          This scheme uses a profile of the RFC 3986 generic URI syntax.\n          All URI fields after the scheme are optional.\n          The \"userinfo\" field uses the traditional \"user:password\" format.\n\nFrom [Provisional RFC for Redis URIs](https://www.iana.org/assignments/uri-schemes/prov/redis)\n\n### Secure a connection with Redis with a mutual TLS\n\nTo support this feature three new environment variables are introduced, TLS_CA_CERT_FILE, TLS_CERT_FILE, TLS_KEY_FILE. Their names are the same as \"redis.conf\" is using. They contain paths to respective files in a mounted secret volume. To use it with Kubernetes pods, add this to a container configuration:\n\n```yaml\nspec:\n  containers:\n  - env:\n      - name: TLS_CA_CERT_FILE\n        value: /certs/ca.crt # path to CA certificate\n      - name: TLS_CERT_FILE\n        value: /certs/tls.crt # path to client certificate\n      - name: TLS_KEY_FILE\n        value: /certs/tls.key # path to client key\n    image: ghcr.io/denist-huma/basic-redis-leaderboard-demo-go:1.2.2\n    name: leaderboard-tls\n    ports:\n    - containerPort: 8080\n      protocol: TCP\n    volumeMounts:\n    - mountPath: /certs\n      name: leaderboard-tls-redis-client-cert\n\n  volumes:\n  - name: leaderboard-tls-redis-client-cert\n    secret:\n      defaultMode: 420\n      secretName: leaderboard-tls-redis-client-cert\n```\n\nWhere the secret \"leaderboard-tls-redis-client-cert\" has all three files we need. Here is a mere description, not the actual data:\n\n```yaml\napiVersion: v1\ndata:\n  tls.crt:  1261 bytes\n  tls.key:  1679 bytes\n  ca.crt:   1415 bytes\nkind: Secret\nmetadata:\n  name: leaderboard-tls-redis-client-cert\ntype: kubernetes.io/tls\n```\n\n#### Run demo\n\n```sh\ngo get\ngo run\n```\n\nFollow: http://localhost:8080\n\n## Try it out\n\n\u003cp\u003e\n    \u003ca href=\"https://heroku.com/deploy\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://www.herokucdn.com/deploy/button.svg\" alt=\"Deploy to Heroku\" width=\"200px\"/\u003e\n    \u003ca\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\n    \u003ca href=\"https://deploy.cloud.run\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://deploy.cloud.run/button.svg\" alt=\"Run on Google Cloud\" width=\"200px\"/\u003e\n    \u003c/a\u003e\n\n    (See notes: How to run on Google Cloud)\n\n\u003c/p\u003e\n\n## How to run on Google Cloud\n\n## 1. Click \"Run on Google Cloud\"\n      \nAdd the right values as per your infrastructure:\n      \n ```\n [ ? ] Value of REDIS_HOST environment variable (Redis server host) \u003cEnter your Redis Host URL\u003e\n [ ? ] Value of REDIS_PORT environment variable (Redis server PORT) \u003cRedis Port\u003e\n [ ? ] Value of REDIS_PASSWORD environment variable (Redis server password) \u003cRedis Password\u003e\n [ ? ] Value of API_PUBLIC_PATH environment variable (Public path to frontend, example `/api/public`) /api/\n [ ? ] Value of IMPORT_PATH environment variable (Path to seed.json file for import, example `/api/seed.json`) seed.json\n [ ? ] Value of API_PORT environment variable (Api public port, example `8080`) 8080\n```\n      \n      \nOpen up the link under \"Manage this application at Cloud Console\" to open up \"Edit and Deploy New Revision”\n\n## 2. Click “Variables and Secrets”\n      \n      \n![](https://raw.githubusercontent.com/redis-developer/basic-redis-leaderboard-demo-go/master/image4.jpg?v=2\u0026s=2)\n      \n## 3. Verify the connector\n      \n![](https://raw.githubusercontent.com/redis-developer/basic-redis-leaderboard-demo-go/master/image2.jpg?v=2\u0026s=2)\n      \n## 3. Access the app\n      \n![](https://raw.githubusercontent.com/redis-developer/basic-redis-leaderboard-demo-go/master/image5.jpg?v=2\u0026s=2) \n      \nHence, you should be able to access this app\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fbasic-redis-leaderboard-demo-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredis-developer%2Fbasic-redis-leaderboard-demo-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fbasic-redis-leaderboard-demo-go/lists"}