Slide 5
Slide 5 text
model/collection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
func SelectCollectionItemsByUserID(ctx context.Context, userID string) ([]*CollectionItem, error) {
var items []*CollectionItem
key := collectionListKey(userID)
err := db.Cache.Get(ctx, key, &items)
if err == nil {
log.Printf("collection items found in Redis for user ID: %s", userID)
return items, nil
}
log.Printf("collection items not found in Redis for user ID: %s, fetching from MySQL: %v", userID, err)
//======//
[MySQLの処理]
//======//
// Redisにコレクションアイテムのリストを保存する
if err := db.Cache.Set(&cache.Item{
Ctx: ctx,
Key: key,
Value: items,
TTL: 7 * 24 * time.Hour,
}); err != nil {
log.Printf("failed to set collection items to Redis for user ID: %s, error: %v", userID, err)
} else {
log.Printf("collection items cached in Redis for user ID: %s", userID)
}
return items, nil
}
コレクションのRedis実装 Flowchart
next:なぜTTL1週間 1