| 74 | } |
| 75 | |
| 76 | func (r *redisCache) nbOfBytes() uint64 { |
| 77 | ctx, cancelFunc := context.WithTimeout(context.Background(), statsTimeout) |
| 78 | defer cancelFunc() |
| 79 | memoryInfo, err := r.client.Info(ctx, "memory").Result() |
| 80 | if err != nil { |
| 81 | log.Errorf("failed to fetch nb of bytes in redis: %s", err) |
| 82 | } |
| 83 | matches := usedMemoryRegexp.FindStringSubmatch(memoryInfo) |
| 84 | |
| 85 | var cacheSize int |
| 86 | |
| 87 | if len(matches) > 1 { |
| 88 | cacheSize, err = strconv.Atoi(matches[1]) |
| 89 | if err != nil { |
| 90 | log.Errorf("failed to parse memory usage with error %s", err) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | return uint64(cacheSize) |
| 95 | } |
| 96 | |
| 97 | func (r *redisCache) Get(key *Key) (*CachedData, error) { |
| 98 | ctx, cancelFunc := context.WithTimeout(context.Background(), getTimeout) |