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
90
20241121_[TechTalk#2]虎の穴ラボでのLLMについて取り組み紹介
toranoana
0
84
社内チャットへ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
380
虎の穴ラボスキルアップ支援制度の利用例
toranoana
0
6.5k
Other Decks in Technology
See All in Technology
強化されたAmazon Location Serviceによる新機能と開発者体験
dayjournal
4
280
Oracle Cloud Infrastructure:2025年6月度サービス・アップデート
oracle4engineer
PRO
2
310
Node-REDのFunctionノードでMCPサーバーの実装を試してみた / Node-RED × MCP 勉強会 vol.1
you
PRO
0
130
AIとともに進化するエンジニアリング / Engineering-Evolving-with-AI_final.pdf
lycorptech_jp
PRO
0
140
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
26k
PHPでWebブラウザのレンダリングエンジンを実装する
dip_tech
PRO
0
220
さくらのIaaS基盤のモニタリングとOpenTelemetry/OSC Hokkaido 2025
fujiwara3
2
280
Liquid Glass革新とSwiftUI/UIKit進化
fumiyasac0921
0
300
Witchcraft for Memory
pocke
1
670
B2C&B2B&社内向けサービスを抱える開発組織におけるサービス価値を最大化するイニシアチブ管理
belongadmin
1
1.3k
rubygem開発で鍛える設計力
joker1007
3
290
整頓のジレンマとの戦い〜Tidy First?で振り返る事業とキャリアの歩み〜/Fighting the tidiness dilemma〜Business and Career Milestones Reflected on in Tidy First?〜
bitkey
1
3.1k
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
328
39k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
24k
Building a Modern Day E-commerce SEO Strategy
aleyda
42
7.4k
Building Adaptive Systems
keathley
43
2.6k
Embracing the Ebb and Flow
colly
86
4.7k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
A Tale of Four Properties
chriscoyier
160
23k
Agile that works and the tools we love
rasmusluckow
329
21k
The Invisible Side of Design
smashingmag
300
51k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
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. ありがとうございました