Skip to content

Instantly share code, notes, and snippets.

@romanitalian
Created August 2, 2018 12:16
Show Gist options
  • Save romanitalian/9d7652e703487ea7241ca45c6ae4343c to your computer and use it in GitHub Desktop.
Save romanitalian/9d7652e703487ea7241ca45c6ae4343c to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
"github.com/go-redis/redis"
)
var RedisClient *redis.Client
func init() {
RedisHost = "host.ru:6379"
RedisPass = ""
RedisDb = 0
}
func main() {
RedisClient = redis.NewClient(&redis.Options{
Addr: RedisHost,
Password: RedisPass,
DB: RedisDb,
})
someCondition := true
val := ""
if someCondition{
cacheKey := "0123456"
val, _ := RedisClient.Get(cacheKey).Result()
if val = "" {
var = "foo"
}
RedisClient.Set(cacheKey, val, 5*time.Minute)
}
fmt.Println(someCondition)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment