๐ฉ
This file contains 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
func init() { | |
fmt.Println("REDIS Connection INIT ------------------------") | |
RAddress, _ = beego.AppConfig.String("redisAddress") | |
RPass, _ = beego.AppConfig.String("redisPassword") | |
RDB, _ = beego.AppConfig.Int("redisDb") | |
RedisClient = redis.NewClient(&redis.Options{ | |
Addr: RAddress, | |
Password: RPass, |
This file contains 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
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) | |
} |
This file contains 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
func GetValue(key string) ([]string, error) { | |
var ctx = context.Background() | |
val, err := RedisClient.SMembers(ctx, key).Result() | |
if err != nil { | |
return nil, err | |
} | |
return val, nil | |
} |
This file contains 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
func DeleteKey(key string) error { | |
var ctx = context.Background() | |
deleteRedisKey := RedisClient.Del(ctx, key) | |
_, err := deleteRedisKey.Result() | |
if err != nil { | |
return err | |
} | |
return nil |
This file contains 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
redisKey := bucketName + `/` + path | |
fromCache, err := redisService.GetValue(redisKey) | |
if err != nil { | |
errResponse.Status = "failed" | |
errResponse.ErrorMessage = err.Error() | |
c.Data["json"] = errResponse | |
c.ServeJSON() | |
return |