Skip to content

Commit 0adba98

Browse files
committed
feat: add prefix for redis keys
1 parent 1d8df60 commit 0adba98

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

internal/cache/redisCache.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ type RedisCache struct {
1616
port string
1717
}
1818

19+
func appendKeyPrefix(key string) string {
20+
return "expo-open-ota:" + key
21+
}
22+
1923
func NewRedisCache(host, password, port string, useTLS bool) *RedisCache {
2024
opts := &redis.Options{
2125
Addr: host + ":" + port,
@@ -42,7 +46,7 @@ func (c *RedisCache) Get(key string) string {
4246
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
4347
defer cancel()
4448

45-
val, err := c.client.Get(ctx, key).Result()
49+
val, err := c.client.Get(ctx, appendKeyPrefix(key)).Result()
4650
if errors.Is(err, redis.Nil) {
4751
return ""
4852
} else if err != nil {
@@ -60,14 +64,14 @@ func (c *RedisCache) Set(key string, value string, ttl *int) error {
6064
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
6165
defer cancel()
6266

63-
return c.client.Set(ctx, key, value, expiration).Err()
67+
return c.client.Set(ctx, appendKeyPrefix(key), value, expiration).Err()
6468
}
6569

6670
func (c *RedisCache) Delete(key string) {
6771
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
6872
defer cancel()
6973

70-
c.client.Del(ctx, key)
74+
c.client.Del(ctx, appendKeyPrefix(key))
7175
}
7276

7377
func (c *RedisCache) Clear() error {

0 commit comments

Comments
 (0)