https://github.com/redis-developer/basic-caching-redis-demo-go-lang
Basic caching redis demo app written in GO language
https://github.com/redis-developer/basic-caching-redis-demo-go-lang
Last synced: 11 months ago
JSON representation
Basic caching redis demo app written in GO language
- Host: GitHub
- URL: https://github.com/redis-developer/basic-caching-redis-demo-go-lang
- Owner: redis-developer
- License: mit
- Created: 2021-02-27T04:17:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-27T07:20:06.000Z (over 2 years ago)
- Last Synced: 2025-04-12T03:52:58.068Z (11 months ago)
- Language: Go
- Size: 3.77 MB
- Stars: 3
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Basic Redis Caching Demo
This app returns the number of repositories a Github account has. When you first search for an account, the server calls Github's API to return the response. This can take 100s of milliseconds. The server then adds the details of this slow response to Redis for future requests. When you search again, the next response comes directly from Redis cache instead of calling Github. The responses are usually usually in a millisecond or so making it blazing fast.
# Overview video
Here's a short video that explains the project and how it uses Redis:
[](https://youtube.com/watch?v=Ov18gLo0Da8)
## How it works?

### 1. How the data is stored:
- Set the number of repositories for the account (use the user name for key): `SETEX `
- E.g `SETEX microsoft 3600 197`
##### Code example:
```Go
err = c.r.Set(username, strconv.Itoa(repo.PublicRepos), time.Hour)
if err != nil {
return nil, err
}
```
### 2. How the data is accessed:
- Get number of public repositories for an account: `GET `
- E.g `GET microsoft`
##### Code example:
```Go
value, err := c.r.Get(username)
if err == redis.Nil {
// ...
```
## How to run it locally?
Make sure you set environment variables (provided in **.env.example**):
```
API_HOST=
API_PORT=5000
API_PUBLIC_PATH=/public
REDIS_HOST=caching-redis
REDIS_PORT=6379
REDIS_PASSWORD=
```
#### Run application
```sh
go run
```
Follow: http://localhost:5000