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
340
Deno Deployと組み合わせるのに Upstashをおすすめしたい
Deno Deployと組み合わせるのに Upstashをおすすめしたい
虎の穴ラボ株式会社
August 31, 2022
Tweet
Share
More Decks by 虎の穴ラボ株式会社
See All by 虎の穴ラボ株式会社
Babylon.js の CSG で遊ぼう!
toranoana
1
77
Deno Queue を使って OGP画像の遅延作成をやってみる
toranoana
1
450
JBUG 京都#1 ボードに機能追加する拡張機能を作った話
toranoana
1
480
JSRにモジュールを公開するまで/公開してから
toranoana
0
82
FreshとHonoでDeno KVを使い倒す
toranoana
1
190
サブカル業界Developers_実践_開発業務でのAIの活用
toranoana
1
390
「エンジニアリングマネージャーのしごと」勉強してみた
toranoana
2
330
【OSC2024 Online/Spring】とらのあなラボの Deno イベント開催の取り組み
toranoana
0
330
【toranoana.deno#15】WebGPUで遊ぼう
toranoana
0
460
Other Decks in Technology
See All in Technology
頼られるのが大好きな 皆さんへ - 支援相手との期待の合わせ方、突き放し方 -/For_people_who_like_to_be_relied_on
naitosatoshi
1
290
スタートアップにおける組織設計とスクラムの長期戦略 / Scrum Fest Kanazawa 2024
yoshikiiida
13
3.6k
エンジニア向け会社紹介資料
caddi_eng
14
220k
Classmethod Odyssey 登壇資料
yamahiro
0
390
ここがすごいよ! AWS Systems Manager!
saichan11
0
1.8k
How to Think Like a Performance Engineer
csswizardry
4
590
GoとアクターモデルでES+CQRSを実践! / proto_actor_es_cqrs
ytake
1
150
スレットハンティングについて知っておきたいこと
hacket
0
130
CTOから見た事業開発とプロダクト開発 / My Perspective on Business and Product Development as CTO
keisuke69
4
960
年間一億円削減した時系列データベースのアーキテクチャ改善~不確実性の高いプロジェクトへの挑戦~
lycorptech_jp
PRO
3
2.9k
Matterport を使ってクラスメソッド各拠点のバーチャルオフィスツアーを作成してみた
wakatsuki
0
160
Azure OpenAI Service Dev Day / LLMでできる!使える!生成AIエージェント
masahiro_nishimi
3
740
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
48
10k
Six Lessons from altMBA
skipperchong
24
3.2k
The Invisible Customer
myddelton
117
13k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
149
45k
Art, The Web, and Tiny UX
lynnandtonic
291
20k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
248
20k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
Automating Front-end Workflow
addyosmani
1362
200k
GitHub's CSS Performance
jonrohan
1026
450k
YesSQL, Process and Tooling at Scale
rocio
166
14k
Happy Clients
brianwarren
94
6.5k
The Art of Programming - Codeland 2020
erikaheidi
48
13k
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. ありがとうございました