Skip to content

Instantly share code, notes, and snippets.

@souvikhaldar
Created October 25, 2018 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save souvikhaldar/136d3595bbaf1a9b8ba26683ab4b3267 to your computer and use it in GitHub Desktop.
Save souvikhaldar/136d3595bbaf1a9b8ba26683ab4b3267 to your computer and use it in GitHub Desktop.
Setting key value pair in redis using go-redis
import "github.com/go-redis/redis"
// Client is setting connection with redis
var redisClient = redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
// SetValue sets the key value pair
func SetValue(key string, value string, expiry time.Duration) error {
errr := redisClient.Set(key, value, expiry).Err()
if errr != nil {
return errr
}
return nil
}
if e := SetValue(phoneNumber, otp, 5*time.Minute); e != nil {
c.JSON(500, oopsies.RecordError(oopsies.QueryExecution, "Error in setting value to redis", e.Error()))
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment