Skip to content
Snippets Groups Projects
Commit 9d466dda authored by Francé Wilke's avatar Francé Wilke
Browse files

Add Redis function GetObjectByKey

parent c618256d
Branches
Tags v1.173.0
No related merge requests found
......@@ -177,6 +177,27 @@ func (r ClientWithHelpers) SetObjectByKeyIndefinitely(key string, object interfa
}
func GetObjectByKey[T any](redisClient *ClientWithHelpers, key string, object T) *T {
// Make sure we have a Redis client, and it is connected
if redisClient == nil || !redisClient.IsConnected() {
return nil
}
// Get the object from Redis
jsonString := redisClient.GetValueByKey(key)
if jsonString == "" {
return nil
}
// Now unmarshal
err := json.Unmarshal([]byte(jsonString), &object)
if err != nil {
return nil
}
return &object
}
func (r ClientWithHelpers) GetValueByKey(key string) string {
if !r.IsConnected() {
return ""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment