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
310
Deno Deployと組み合わせるのに Upstashをおすすめしたい
Deno Deployと組み合わせるのに Upstashをおすすめしたい
虎の穴ラボ株式会社
August 31, 2022
Tweet
Share
More Decks by 虎の穴ラボ株式会社
See All by 虎の穴ラボ株式会社
FreshとHonoでDeno KVを使い倒す
toranoana
1
43
サブカル業界Developers_実践_開発業務でのAIの活用
toranoana
1
280
「エンジニアリングマネージャーのしごと」勉強してみた
toranoana
2
250
【OSC2024 Online/Spring】とらのあなラボの Deno イベント開催の取り組み
toranoana
0
280
【toranoana.deno#15】WebGPUで遊ぼう
toranoana
0
310
App Router による Web 開発について
toranoana
0
93
Fresh(Deno)をプラグインで拡張しよう!
toranoana
0
210
Freshプラグインのテストもプラグインを使うと捗る!
toranoana
0
120
個人開発アプリにスキーマ 駆動開発を取り入れた話
toranoana
0
80
Other Decks in Technology
See All in Technology
継続的な改善 x ⾮連続的な進化
sansantech
PRO
3
150
SPI原点回帰論:事業課題とFour Keysの結節点を見出す実践的ソフトウェアプロセス改善 / DevOpsDays Tokyo 2024
visional_engineering_and_design
4
1.9k
反実仮想機械学習とは何か
usaito
PRO
11
4.2k
Azure犬駆動開発の記録/GlobalAzureFukuoka2024_20240420
nina01
1
210
アクセス制御にまつわる改善 / Improving access control
itkq
0
530
Google Cloud Next '24でブログを10本書いた方法と勉強会を沸かせた方法
yasumuusan
0
290
推しは推せるときに推せ! プロダクトにフィードバックしていこう
nakasho
0
290
現代CSSフレームワークの内部実装とその仕組み
poteboy
8
3.6k
TechFeed Experts Night#27 〜 フロントエンドフレームワーク最前線 (Svelte)
baseballyama
1
400
Tellus の衛星データを見てみよう #mf_fukuoka
kongmingstrap
0
170
コンパウンドスタートアップのためのスケーラブルでセキュアなInfrastructure as Codeパイプラインを考える / Scalable and Secure Infrastructure as Code Pipeline for a Compound Startup
yuyatakeyama
4
4.7k
MapLibreとAmazon Location Service
dayjournal
1
150
Featured
See All Featured
Building Applications with DynamoDB
mza
88
5.6k
WebSockets: Embracing the real-time Web
robhawkes
59
7k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
116
18k
Imperfection Machines: The Place of Print at Facebook
scottboms
260
12k
Art, The Web, and Tiny UX
lynnandtonic
289
19k
10 Git Anti Patterns You Should be Aware of
lemiorhan
648
58k
What the flash - Photography Introduction
edds
64
11k
Statistics for Hackers
jakevdp
789
220k
How GitHub (no longer) Works
holman
304
140k
Making Projects Easy
brettharned
108
5.5k
Robots, Beer and Maslow
schacon
PRO
155
7.9k
A Philosophy of Restraint
colly
197
16k
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. ありがとうございました