Created
February 24, 2020 21:43
-
-
Save brachi-wernick/c615e5c7257dc3bfb106406f7d780d3d to your computer and use it in GitHub Desktop.
get redis api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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