appdata-patch
Some checks failed
deploy / deploy (push) Failing after 5s

This commit is contained in:
2024-02-22 10:40:39 +03:00
parent 94917e7735
commit 8fca4cf4c0
4 changed files with 47 additions and 95 deletions

View File

@@ -1,27 +0,0 @@
package redis
import (
"fmt"
)
// GetUserProfile возвращает профиль пользователя в виде сырого JSON
func (c *provider) GetUserProfile(userId string) (string, error) {
key := fmt.Sprintf("user:%s:profile", userId)
profileJSON, err := c.store.Get(c.ctx, key).Result()
if err != nil {
return "", err
}
return profileJSON, nil
}
// GetUserFollows возвращает список подписок пользователя в виде сырого JSON
func (c *provider) GetUserFollows(userId string) (string, error) {
key := fmt.Sprintf("user:%s:follows", userId)
followsJSON, err := c.store.Get(c.ctx, key).Result()
if err != nil {
return "", err
}
return followsJSON, nil
}

View File

@@ -218,3 +218,26 @@ func (c *provider) GetBoolStoreEnvVariable(key string) (bool, error) {
return data == "1", nil
}
// GetUserAppDataFromRedis retrieves user profile and follows from Redis, combines them into a JSON format,
// and assigns the JSON string to the provided user's ID.
func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) {
// Retrieve user data from Redis
key := fmt.Sprintf("user:%s:author", userId)
authorJSON, err := c.store.Get(c.ctx, key).Result()
if err != nil {
return "", err
}
key = fmt.Sprintf("user:%s:follows", userId)
followsJSON, err := c.store.Get(c.ctx, key).Result()
if err != nil {
return "", err
}
// Combine user data into a JSON string
combinedData := fmt.Sprintf(`{"profile": %s, "follows": %s}`, authorJSON, followsJSON)
return combinedData, nil
}