A brief introduction to Redis
Introduction
The discussion about Redis is actually a cliché issue in the current backend development, and is basically a basic examination point for backend development interviews. The background introduction and detailed description of Redis will not be described here. No matter how you introduce it, the core is that Redis is a memory-based key-value multi-data structure storage and can provide persistent services. Memory-based characteristics determine that Redis is naturally suitable for high-concurrency data read and write cache optimization, and it also brings about excessive memory overhead. So in some specific situations, Redis is a powerful weapon that is always bad, worthy of in-depth learning.
Install redis and run the following go code:
package main import ( "time" "fmt" "/go-redis/redis" ) var Client * func init() { Client = (&{ Addr: "127.0.0.1:6379", PoolSize: 1000, ReadTimeout: * (100), WriteTimeout: * (100), IdleTimeout: * (60), }) _, err := ().Result() if err != nil { panic("init redis error") } else { ("init redis ok") } } func get(key string) (string, bool) { r, err := (key).Result() if err != nil { return "", false } return r, true } func set(key string, val string, expTime int32) { (key, val, (expTime) * ) } func main() { set("name", "x", 100) s, b := get("name") (s, b) }
result:
init redis ok
x true
The expiration time is 100s. After expiration, get cannot obtain information, and nil is returned
Simple, I won't say much.
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for your study or work. Thank you for your support. If you want to know more about it, please see the following links