Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Deno Deployと組み合わせるのに Upstashをおすすめしたい
Search
虎の穴ラボ株式会社
August 31, 2022
Technology
0
420
Deno Deployと組み合わせるのに Upstashをおすすめしたい
Deno Deployと組み合わせるのに Upstashをおすすめしたい
虎の穴ラボ株式会社
August 31, 2022
Tweet
Share
More Decks by 虎の穴ラボ株式会社
See All by 虎の穴ラボ株式会社
Tailwind CSSとAtomic Designで実現する効率的な Web 開発の事例
toranoana
1
480
Denoについて、同人誌記事を出しました+update
toranoana
0
150
【虎の穴ラボ Tech Talk #2】プロンプトエンジニアリング
toranoana
0
88
20241121_[TechTalk#2]虎の穴ラボでのLLMについて取り組み紹介
toranoana
0
82
社内チャットへRAG導入した話(Tech Talk #2)
toranoana
0
150
Deno Deploy で Web Cache API を 使えるようになったので試した知見
toranoana
1
510
【虎の穴ラボ Tech Talk】虎の穴ラボTech Talk説明資料
toranoana
0
350
虎の穴ラボ Tech Talk_CDKでFargate環境構築
toranoana
1
370
虎の穴ラボスキルアップ支援制度の利用例
toranoana
0
6.5k
Other Decks in Technology
See All in Technology
製造業からパッケージ製品まで、あらゆる領域をカバー!生成AIを利用したテストシナリオ生成 / 20250627 Suguru Ishii
shift_evolve
PRO
1
160
Tech-Verse 2025 Global CTO Session
lycorptech_jp
PRO
0
1.1k
Yamla: Rustでつくるリアルタイム性を追求した機械学習基盤 / Yamla: A Rust-Based Machine Learning Platform Pursuing Real-Time Capabilities
lycorptech_jp
PRO
4
170
Witchcraft for Memory
pocke
1
650
LangSmith×Webhook連携で実現するプロンプトドリブンCI/CD
sergicalsix
1
140
整頓のジレンマとの戦い〜Tidy First?で振り返る事業とキャリアの歩み〜/Fighting the tidiness dilemma〜Business and Career Milestones Reflected on in Tidy First?〜
bitkey
0
170
生成AI開発案件におけるClineの業務活用事例とTips
shinya337
0
160
「Chatwork」の認証基盤の移行とログ活用によるプロダクト改善
kubell_hr
1
230
Should Our Project Join the CNCF? (Japanese Recap)
whywaita
PRO
0
280
OPENLOGI Company Profile for engineer
hr01
1
33k
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
26k
GitHub Copilot の概要
tomokusaba
1
140
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.4k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.8k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
4 Signs Your Business is Dying
shpigford
184
22k
What's in a price? How to price your products and services
michaelherold
246
12k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
The Cost Of JavaScript in 2023
addyosmani
51
8.5k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
500
Transcript
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. 2022/08/24 toranoana.deno
#8 虎の穴ラボ 奥谷 一陽 Deno Deployと組み合わせるのに upstashをおすすめしたい
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. 自己紹介 奥谷
一陽 所属:虎の穴ラボ株式会社 担当:とらコインSHOPなど新規事業系の開発 興味:TypeScript、Deno おすすめコンテンツ: 『プラネテス』 『暴太郎戦隊ドンブラザーズ』 Twitter:@okutann88
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. Deno Deploy
どのくらい使っ てますか?
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. Deno Deploy
と組み合わせる前提で、 オススメSaaSを紹介したい
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. upstash
参考:https://upstash.com/
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. upstash -
カルフォルニアの Upstash, Inc. が運営するSaaS - Redis Kafka qStashを提供 - キーワード:グローバル 低レイテンシ 上限付きの従量課金
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. upstash の
Redis - 無料プラン:10K コマンド/日 - 有料プラン:0.2 $/100Kコマンド、月間最大 $120 まで - 公式が、deno.land/x にモジュールを公開済み https://deno.land/x/
[email protected]
- Redisと銘打つものの、内部でfetchが使用されたhttpリクエストを使用 「Redisっぽく動く」 「Redis互換の」ぐらいの感触
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. upstash の
Redis の使用例 import { Application, Router, Context } from "https://deno.land/x/oak/mod.ts"; import { Redis } from "https://deno.land/x/upstash_redis/mod.ts"; const redis = new Redis({ url: Deno.env.get("UPSTASH_URL"), token: Deno.env.get("UPSTASH_TOKEN"), }); const router = new Router(); router.get("/", async (context: Context) => { const count = await redis.get("count"); context.response.body = count; }); router.post("/update", async (context: Context) => { await redis.incr("count"); context.response.body = "updated"; }); const app = new Application(); app.use(router.routes()); app.use(router.allowedMethods()); await app.listen({ port: 8080 });
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. upstash の
Redis で実際にやりたいのは? - キャッシュの仕組みが有ったときに、Webサービスで扱いたいのは 「セッション」では無いだろうか(偏見かもしれません) - oak_session モジュール + upstash_redis モジュール は組み合わせ可能? => できる ただし...、 オプションが必須
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. upstash の
Redis を oak_session で使う import { Application, Context, Router } from "https://deno.land/x/oak/mod.ts"; import { RedisStore, Session } from "https://deno.land/x/oak_sessions/mod.ts"; import { Redis } from "https://deno.land/x/upstash_redis/mod.ts"; const redis = new Redis({ url: Deno.env.get("UPSTASH_URL")!, token: Deno.env.get("UPSTASH_TOKEN")!, automaticDeserialization: false, // <== ポイント }); const router = new Router(); router.get("/", async (context: Context) => { const name = await context.state.session.get("name"); context.response.body = ` <!DOCTYPE html> <html> <body> <div> ${!name ? "" : "name=" + name} </div> <form method="POST"> <input name="name"> <button type="submit">submit</button> </form> </body> </html> `; }); router.post("/", async (context: Context) => { const form = await context.request.body({ type: "form" }).value; const name = form.get("name"); if (!!name) context.state.session.set("name", name); context.response.redirect("/"); }); type AppState = { session: Session; }; const app = new Application<AppState>(); const store = new RedisStore(redis); app.use(Session.initMiddleware(store)); app.use(router.routes()); app.use(router.allowedMethods()); await app.listen({ port: 8080 }); upstash_redisは、デフォルトで、jsonの自動デシリアライズが ONになっているので この機能を停止させる デシリアライズは、oak_session に任せる!
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. qStash ?
- upstashの独自サービス - サーバーレス、エッジランタイム向け、HTTPベースメッセージング/ スケジューリングソリューション - 無料プラン:50リクエスト/日 - 有料プラン:50Kリクエスト/日 0.4 $/1Kリクエスト 月間最大 $450 - 最大のポイント Deno Deploy をスケジュール実行できる => さらに、upstash公式が deno deploy をサポート
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. qStash の
deno deploy サポート
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. Deno Deployで
qStash 使ってみる 以下の内容を実装する - qStashから1分に1回 Deno Deploy に置いたアプリを呼び出す - 呼び出しに対応して upstash Redisに保管した値をカウントする - ブラウザからアクセスし値を参照する
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. Deno Deployで
qStash 使ってみる ポイント - 公式が、deno.land/x にモジュールを公開済み - https://deno.land/x/
[email protected]
- qStashからのリクエストであることを upstash_qstash モジュールを 使い検証すること
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. Deno Deploy
で qStash を使う実装例 import { Application, Router, Context } from "https://deno.land/x/oak/mod.ts"; import { Redis } from "https://deno.land/x/upstash_redis/mod.ts"; import { Receiver } from "https://deno.land/x/upstash_qstash/mod.ts"; const redis = new Redis({ url: Deno.env.get("UPSTASH_URL"), token: Deno.env.get("UPSTASH_TOKEN"), }) const receiver = new Receiver({ currentSigningKey: Deno.env.get("QSTASH_CURRENT_SIGNING_KEY")!, nextSigningKey: Deno.env.get("QSTASH_NEXT_SIGNING_KEY")!, }); const router = new Router(); router.get("/", async(context:Context) => { const count = await redis.get("count"); context.response.body = count; }); router.post("/update", async(context:Context) => { const isValid = await receiver.verify({ // <== ポイント signature: context.request.headers.get("Upstash-Signature")!, body: await context.request.body({ type: "text" }).value, }).catch((err: Error) => { console.error(err); return false; }); if (!isValid) { return new Response("Invalid signature", { status: 401 }); } await redis.incr("count"); return new Response("OK", { status: 200 }); }); const app = new Application(); app.use(router.routes()); app.use(router.allowedMethods()); await app.listen({ port: 8080 });
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. 現在動作中です。 一分に一回カウントアップされます。
https://late-otter-59.deno.dev/
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. まとめ -
Deno Deployの有効活用のため、upstashの組み合わせオススメ - 出来ることが、大きく広がる - Deno Deploy 起点のフルサーバーレスなサービスを開発できる可能性 例えば?
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. Deno Deploy
起点フルサーバーレス サービス インフラ 構想 deno deploy ・APIサーバー ・DB管理 ・ストレージ キャッシュ呼び出し Redis qStash バッチ処理呼び出し フロントサーバー
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. Deno Deploy
起点フルサーバーレス サービス インフラ 構想 deno deploy フロントサーバー ・APIサーバー ・DB管理 ・ストレージ キャッシュ呼び出し Redis qStash バッチ処理呼び出し deno deploy + + bunny cdn ... API呼び出し
Copyright (C) 2021 Toranoana Inc. All Rights Reserved. ありがとうございました