Skip to content

Instantly share code, notes, and snippets.

@Masum-Osman
Created July 4, 2022 07:33
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 Masum-Osman/380f2a6fba8d323bd7e600e87846d0b5 to your computer and use it in GitHub Desktop.
Save Masum-Osman/380f2a6fba8d323bd7e600e87846d0b5 to your computer and use it in GitHub Desktop.
func SetValue(key string, value string) (string, error) {
var ctx = context.Background()
err := RedisClient.SAdd(ctx, key, value).Err()
if err != nil {
log.Fatalf("Failed to Set value: %v", err)
}
shouldExpireOn := time.Now().Add(time.Second * 604000)
expireKeyValue := RedisClient.ExpireAt(ctx, key, shouldExpireOn)
retrunValue, err := expireKeyValue.Result()
if err != nil {
return "nil", err
}
if !retrunValue {
return "failed to set expire time", err
}
return "success", nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment