Show how the redis works with Golang.
- The AAPL's details - market cap of 2,6 triillions and USA origin - are stored in a hash like below:
- E.g
HSET "company:AAPL" symbol "AAPL" market_cap "2600000000000" country USA
- E.g
- The Ranks of AAPL of 2,6 trillions are stored in a ZSET.
- E.g
ZADD companyLeaderboard 2600000000000 company:AAPL
- E.g
- Top 10 companies:
- E.g
ZREVRANGE companyLeaderboard 0 9 WITHSCORES
- E.g
- All companies:
- E.g
ZREVRANGE companyLeaderboard 0 -1 WITHSCORES
- E.g
- Bottom 10 companies:
- E.g
ZRANGE companyLeaderboard 0 9 WITHSCORES
- E.g
- Between rank 10 and 15:
- E.g
ZREVRANGE companyLeaderboard 9 14 WITHSCORES
- E.g
- Show ranks of AAPL, FB and TSLA:
- E.g
ZSCORE companyLeaderBoard company:AAPL company:FB company:TSLA
- E.g
- Adding market cap to companies:
- E.g
ZINCRBY companyLeaderBoard 1000000000 "company:FB"
- E.g
- Reducing market cap to companies:
- E.g
ZINCRBY companyLeaderBoard -1000000000 "company:FB"
- E.g
- Companies over a Trillion:
- E.g
ZCOUNT companyLeaderBoard 1000000000000 +inf
- E.g
- Companies between 500 billion and 1 trillion:
- E.g
ZCOUNT companyLeaderBoard 500000000000 1000000000000
- E.g
func (c Controller) Top10() ([]*Company, error) {
companies, err := c.r.ZRevRange(keyLeaderBoard, 0, 9)
if err != nil {
return nil, err
}
c.buildCompanies(companies)
c.buildRanks(companies)
return companies, nil
}
- REDIS_HOST: Redis server host
- REDIS_PORT: Redis server port
- REDIS_PASSWORD: Password to the server
go get
go run
Follow: http://localhost:5000
(See notes: How to run on Google Cloud)
Add the right values as per your infratsructure:
[ ? ] Value of REDIS_HOST environment variable (Redis server host) <Enter your Redis Host URL>
[ ? ] Value of REDIS_PORT environment variable (Redis server PORT) <Redis Port>
[ ? ] Value of REDIS_PASSWORD environment variable (Redis server password) <Redis Password>
[ ? ] Value of API_PUBLIC_PATH environment variable (Public path to frontend, example `/api/public`) /api/
[ ? ] Value of IMPORT_PATH environment variable (Path to seed.json file for import, example `/api/seed.json`) seed.json
[ ? ] Value of API_PORT environment variable (Api public port, example `5000`) 5000
Open up the link under "Manage this application at Cloud Console" to open up "Edit and Deploy New Revision”
Hence, you should be able to access Rate Limiting app