Created
October 25, 2018 11:25
-
-
Save souvikhaldar/136d3595bbaf1a9b8ba26683ab4b3267 to your computer and use it in GitHub Desktop.
Setting key value pair in redis using go-redis
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
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