This commit is contained in:
@@ -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
|
||||
}
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user