Skip to content

Commit

Permalink
Merge pull request #19 from solufit/17-redis-cacheに書き込み時のtimeout指定忘れ
Browse files Browse the repository at this point in the history
Refactor cache creation to set expiration time
  • Loading branch information
Walkmana-25 authored Oct 2, 2024
2 parents 2e3ff4c + 2746e69 commit 0b32ee6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cache

import (
"context"
"time"

"fmt"

Expand Down Expand Up @@ -63,7 +64,9 @@ func createEventCache(redisClient *redis.Client, key Id, event string, channel c
ctx := context.Background()

// 一週間分のキャッシュデータを作成する
_, err := redisClient.Set(ctx, string(key), event, 0).Result()
day := 7
expire := time.Duration(day*24) * time.Hour
_, err := redisClient.Set(ctx, string(key), interface{}(event), expire).Result()

if err != nil {
channel <- err
Expand Down

0 comments on commit 0b32ee6

Please sign in to comment.