Skip to content

Instantly share code, notes, and snippets.

@brachi-wernick
Created February 24, 2020 21:43
Show Gist options
  • Save brachi-wernick/c615e5c7257dc3bfb106406f7d780d3d to your computer and use it in GitHub Desktop.
Save brachi-wernick/c615e5c7257dc3bfb106406f7d780d3d to your computer and use it in GitHub Desktop.
get redis api
var rdb *redis.ClusterClient
func main() {
mux := goji.NewMux()
mux.HandleFunc(pat.Get("/hello/:name"), hello)
mux.HandleFunc(pat.Get("/get"), get)
rdb = createRedis()
http.ListenAndServe(":8099", mux)
}
func get(w http.ResponseWriter, r *http.Request) {
userId := rand.Intn(1000000)
userKey := "{"+ strconv.Itoa(userId) + "}" + strconv.Itoa(userId)
fmt.Printf("userKey: %s", userKey)
val, err := rdb.Get(userKey).Result()
if err == redis.Nil {
fmt.Fprint(w, "[]")
} else if err != nil {
panic(err)
} else {
fmt.Fprint(w, string(val))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment