TECH |
Engadget Japanese |
HAKUBAのカメラアクセサリーがAmazonでセール中。ドライボックスや三脚、一脚などがおトク価格に |
https://japanese.engadget.com/hakuba-sale-053830563.html
|
amazon |
2021-07-07 05:38:30 |
TECH |
Engadget Japanese |
米バイデン大統領が「修復する権利」規則作りをFTCに指示か(Bloomberg報道) |
https://japanese.engadget.com/president-biden-order-ftc-repair-053040181.html
|
bloomberg |
2021-07-07 05:30:40 |
TECH |
Engadget Japanese |
Googleマップの屋内ARナビ提供開始。東京駅などJR東日本の主要駅で利用可能 |
https://japanese.engadget.com/google-map-indoor-ar-navi-050037019.html
|
利用可能 |
2021-07-07 05:00:37 |
ROBOT |
ロボスタ |
渋谷区立宮下公園をVR空間上に再現「渋谷区立宮下公園 パラレルサイト」ブラウザとVRChatでオープン アート展、スケボーや花火等を楽しめる |
https://robotstart.info/2021/07/07/shibuya-miyashita-park-vr.html
|
vrchat |
2021-07-07 05:06:31 |
IT |
ITmedia 総合記事一覧 |
[ITmedia ビジネスオンライン] 高校生が好きなコーヒーチェーン 1位は「スタバ」、2位は? |
https://www.itmedia.co.jp/business/articles/2107/07/news107.html
|
itmedia |
2021-07-07 14:24:00 |
IT |
ITmedia 総合記事一覧 |
[ITmedia Mobile] なか卯の「モバイルオーダー」が店内に対応 券売機不要で注文可能に |
https://www.itmedia.co.jp/mobile/articles/2107/07/news106.html
|
itmediamobile |
2021-07-07 14:22:00 |
IT |
ITmedia 総合記事一覧 |
[ITmedia News] 「ROCK IN JAPAN」開催中止 県医師会などの要請に「何をもって万全とするのか」 |
https://www.itmedia.co.jp/news/articles/2107/07/news104.html
|
itmedia |
2021-07-07 14:18:00 |
IT |
ITmedia 総合記事一覧 |
[ITmedia PC USER] エイサー、法人向けの21.5型/23.8型フルHD液晶ディスプレイ |
https://www.itmedia.co.jp/pcuser/articles/2107/07/news103.html
|
itmediapcuser |
2021-07-07 14:08:00 |
IT |
ITmedia 総合記事一覧 |
[ITmedia News] 新型Switchのちぐはぐな仕様、狙いは“巣ごもり携帯機”? 新機能を読み解く |
https://www.itmedia.co.jp/news/articles/2107/07/news105.html
|
itmedia |
2021-07-07 14:04:00 |
TECH |
Techable(テッカブル) |
ミニマリストなAppleデバイスユーザーに! デバイスの整頓と無線充電ができる「StudioCaddy」 |
https://techable.jp/archives/157750
|
apple |
2021-07-07 05:00:41 |
IT |
情報システムリーダーのためのIT情報専門サイト IT Leaders |
ペガジャパン、ローコード開発ツール新版「Pega Infinity 8.6」、UIの開発を容易に | IT Leaders |
https://it.impress.co.jp/articles/-/21733
|
ペガジャパン、ローコード開発ツール新版「PegaInfinity」、UIの開発を容易にITLeaders米Pegasystemsの日本法人、ペガジャパンは年月日、ローコード開発ツール製品群の新版「PegaInfinity」を発表した。 |
2021-07-07 14:35:00 |
AWS |
AWS Japan Blog |
MLflow と Amazon SageMaker による機械学習のライフサイクル管理 |
https://aws.amazon.com/jp/blogs/news/machine-learning-managing-your-machine-learning-lifecycle-with-mlflow-and-amazon-sagemaker/
|
SageMakerは、開発者やデータサイエンティストがMLモデルの迅速な構築、学習、デプロイを支援するフルマネージドサービスです。 |
2021-07-07 05:17:35 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
AWSでAIサービスを使ってみる〜①導入編〜 |
https://qiita.com/AInosukey/items/165ae14483ef17ed1bdf
|
pythonのインストールMacにPython開発環境をインストールするAWSCLIのインストールpipinstallawscliupgradeSuccessfulinstalledが表示されればインストール完了AWSCLIのインストール確認awsversionAWSCLIのバージョンが確認できれば成功アクセスキーの設定awsconfigureIAMユーザーを作成された際にメモした、AWSアクセスキーID、AWSシークレットアクセスキー、デフォルトリージョンを入力DefaultregionnameNoneデフォルトの出力形式はjsonと入力し、エラーメッセージが表示されず終了したらアクセスキーの設定は完了。 |
2021-07-07 14:04:25 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
win32comでExcel2019の架空のデータをピボットテーブルにしたいがAttributeError: xlDataBaseとエラーが出てしまいます |
https://teratail.com/questions/348164?rss=all
|
wincomでExcelの架空のデータをピボットテーブルにしたいがAttributeErrorxlDataBaseとエラーが出てしまいますpythonからExcelのデータをピボットテーブルにしたいPythonnbspからnbspExcelnbspを編集し、ピボットテーブルを作成するこちらを参考にピボットテーブルにできるかどうか調べています。 |
2021-07-07 14:56:51 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
strcpy_s()関数でアクセスエラーが発生する原因が知りたい。 |
https://teratail.com/questions/348163?rss=all
|
strcpys関数でアクセスエラーが発生する原因が知りたい。 |
2021-07-07 14:55:20 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
unity steamVRについて |
https://teratail.com/questions/348162?rss=all
|
unitysteamVRについてunityにて、Assetnbspstoreから、steamVRnbspPluginをインポートしたいのですが、AssemblynbsphasnbspreferencenbsptonbspnonexistentnbspassemblynbspaposUnityXROpenVRaposnbspAssetsSteamVRSteamVRasmdef警告が毎回出てしまいます。 |
2021-07-07 14:52:54 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
複数の変数に同じ処理をかけたい |
https://teratail.com/questions/348161?rss=all
|
複数の変数に同じ処理をかけたい実現したいこと・試したこと複数の変数datacustomerCode、dataarrivalDate、apple、orangeなどなど・・・に対して、もしnullもしくはundefinedであればハイフンに変換する、という処理を行いたいです。 |
2021-07-07 14:51:13 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
パーティクルの発生位置について |
https://teratail.com/questions/348160?rss=all
|
パーティクルの発生位置についてparticlesminjsで表示するパーティクルの発生位置についてparticlesminjsと以下のサイトを参照して、左から右に流れるパーティクルを作成いたしました。 |
2021-07-07 14:50:21 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
FOR文内で連番をつける |
https://teratail.com/questions/348159?rss=all
|
FOR文内で連番をつけるバッチ処理でファイル移動時にファイル名を変更し、連番をつける。 |
2021-07-07 14:49:05 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
twitter APIの切り替え |
https://teratail.com/questions/348158?rss=all
|
twitterAPIの切り替え統計ソフトのRのrtweetパッケージを用いて、nbspTwitterのテキストマイニングを行っています。 |
2021-07-07 14:27:31 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
バッチ処理でサーバへの接続したい |
https://teratail.com/questions/348157?rss=all
|
バッチ処理でサーバへの接続したいバッチ処理のファイルを作成しています。 |
2021-07-07 14:25:03 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
DjangoでAWSのS3にIAM roleを使ってアクセスする方法 |
https://teratail.com/questions/348156?rss=all
|
画像の保存場所をWEBサーバーECからSに変更するため、ECに、Sのフルアクセス権限AWS管理ポリシーを持つIAMnbsproleをアタッチしました。 |
2021-07-07 14:25:00 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
[WordPress] single.phpを作る前に投稿した記事がうまく個別ページ表示されない |
https://teratail.com/questions/348155?rss=all
|
WordPresssinglephpを作る前に投稿した記事がうまく個別ページ表示されない困っていることWordPressでテーマファイルを作っているのですがはじめは詳細ページはいらないと言われ、singlephpは設けず投稿にアップした記事をTOPページにのみ一覧表示させていたのですがやっぱり、詳細ページも欲しいと後から言われ、singlephpを設けて設定してみたのですが、このファイルを作る前に作った記事の詳細が表示されず、TOPページのビジュアルになりますパーマリンクは個別ページ。 |
2021-07-07 14:24:15 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
protoc コマンドって結局どれが正しいのでしょうか?(gRPC、protobuf) |
https://teratail.com/questions/348154?rss=all
|
protocコマンドって結局どれが正しいのでしょうかgRPC、protobuf前提・実現したいことgRPCを勉強中です。 |
2021-07-07 14:23:21 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
Discord.py コマンド実行で特定のチャンネルへメッセージを送信したい |
https://teratail.com/questions/348153?rss=all
|
Discordpyコマンド実行で特定のチャンネルへメッセージを送信したいコマンドtestを実行すると指定したテキストチャンネルへメッセージを送信するbotを作成しています。 |
2021-07-07 14:23:19 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
wordpressのショートコードで配列内の値を出力させたい |
https://teratail.com/questions/348152?rss=all
|
wordpressのショートコードで配列内の値を出力させたいいつもお世話になっております。 |
2021-07-07 14:14:24 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
サブクエリとleft joinを用いたクエリビルダの書き方について |
https://teratail.com/questions/348151?rss=all
|
サブクエリとleftjoinを用いたクエリビルダの書き方についてSELECTAFROMサブクエリXASNOWLEFTJOINサブクエリYASPREVONNOWidPREVidサブクエリの中身は、selectnbspAnbspfromnbspBnbspgroupnbspbynbspAのように入っています。 |
2021-07-07 14:08:29 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
GAS(Google App Script)の新しいエディターでのオートコンプリートを非表示にしたい。 |
https://teratail.com/questions/348150?rss=all
|
GASGoogleAppScriptの新しいエディターでのオートコンプリートを非表示にしたい。 |
2021-07-07 14:05:01 |
Ruby |
Rubyタグが付けられた新着投稿 - Qiita |
ユークリッドの互除法の実装【Rubyアルゴリズム】 |
https://qiita.com/q_zoq/items/4b4455f38952dfedb3a9
|
|
2021-07-07 14:08:57 |
AWS |
AWSタグが付けられた新着投稿 - Qiita |
AWS, Azure, GCP 3つのクラウドサービスを比較 |
https://qiita.com/dtakkiy/items/3592d4e94b3610ebc54a
|
マルチクラウドマルチクラウドとは、いずれか一社のクラウドサービスを利用するのではなく、利用目的に応じて複数のクラウドサービスを連携し利用すること。 |
2021-07-07 14:47:49 |
AWS |
AWSタグが付けられた新着投稿 - Qiita |
AWSでAIサービスを使ってみる〜①導入編〜 |
https://qiita.com/AInosukey/items/165ae14483ef17ed1bdf
|
pythonのインストールMacにPython開発環境をインストールするAWSCLIのインストールpipinstallawscliupgradeSuccessfulinstalledが表示されればインストール完了AWSCLIのインストール確認awsversionAWSCLIのバージョンが確認できれば成功アクセスキーの設定awsconfigureIAMユーザーを作成された際にメモした、AWSアクセスキーID、AWSシークレットアクセスキー、デフォルトリージョンを入力DefaultregionnameNoneデフォルトの出力形式はjsonと入力し、エラーメッセージが表示されず終了したらアクセスキーの設定は完了。 |
2021-07-07 14:04:25 |
Docker |
dockerタグが付けられた新着投稿 - Qiita |
SpringBootからDockerHubのMySQLに接続する設定 |
https://qiita.com/axs-dev/items/0245fe0db46333ab21f5
|
はじめにdockerhubのmysqlをローカルで使用して結合テストしようとしてハマりました。 |
2021-07-07 14:19:37 |
GCP |
gcpタグが付けられた新着投稿 - Qiita |
AWS, Azure, GCP 3つのクラウドサービスを比較 |
https://qiita.com/dtakkiy/items/3592d4e94b3610ebc54a
|
マルチクラウドマルチクラウドとは、いずれか一社のクラウドサービスを利用するのではなく、利用目的に応じて複数のクラウドサービスを連携し利用すること。 |
2021-07-07 14:47:49 |
Azure |
Azureタグが付けられた新着投稿 - Qiita |
AWS, Azure, GCP 3つのクラウドサービスを比較 |
https://qiita.com/dtakkiy/items/3592d4e94b3610ebc54a
|
マルチクラウドマルチクラウドとは、いずれか一社のクラウドサービスを利用するのではなく、利用目的に応じて複数のクラウドサービスを連携し利用すること。 |
2021-07-07 14:47:49 |
技術ブログ |
Developers.IO |
ECSのタスク起動時に「standard_init_linux.go」関連のエラーが出た場合の対処方法 |
https://dev.classmethod.jp/articles/how-to-fix-standard-init-linux-error/
|
standardinitlinuxgo |
2021-07-07 05:47:11 |
技術ブログ |
Developers.IO |
AWSアカウントの本番環境でケアレスミスを起こさないために意識していること |
https://dev.classmethod.jp/articles/to-avoid-making-careless-mistakes-with-aws-account/
|
yuimayforblue |
2021-07-07 05:35:40 |
技術ブログ |
Developers.IO |
[Safari] SafariのWebインスペクタでタブがうまく表示できなかったのでSafari Technology Previewを使った |
https://dev.classmethod.jp/articles/safari-technology-preview-web-inspector/
|
iphone |
2021-07-07 05:30:51 |
技術ブログ |
Developers.IO |
Step Functions Workflow Studio を利用して、EC2インスタンス開始30分後にEC2を停止するワークフローを組んでみた |
https://dev.classmethod.jp/articles/step-functions-workflow-studio-create-workflow-to-stop-ec2/
|
functionsworkflowstudio |
2021-07-07 05:27:43 |
海外TECH |
DEV Community |
Using Serverless Redis as Database for Netlify Functions |
https://dev.to/myogeshchavan97/using-serverless-redis-as-database-for-netlify-functions-2mii
|
Using Serverless Redis as Database for Netlify FunctionsIn this tutorial we ll see how we can use Redis as a database for caching purposes to load the data faster in any type of application So let s get started What is RedisRedis is an in memory data store used as a database for storing dataRedis is used for caching purpose So If your API data is not frequently changing then we can cache the previous API result data and on the next requests re send the cached data from RedisAs you know some websites which show live score of matches like cricket match updates the data on the website after every fixed second So If the user clicks on the refresh button or refreshes the page the cached data is returned to avoid the unnecessary heavy load on the server And after specific seconds of time the fresh score of data gets updated which is done using Redis databaseSo If you re making an API call to some external API or your MongoDB PostgreSQL or any other database you can return the cached result from Redis If your data is not changing frequentlyRedis is not specific to one langauge you can use redis in PHP C C Ruby Scala Swift and so onTop companies like Twitter GitHub StackOverflow Pinterest and many others are using Redis in their applicationsRedis also accepts expiry time so If your API data is changing after seconds you can specify the expiry time in Redis to re fetch the new data after seconds instead of sending cached dataThe data stored in the Redis is always in the string formatSo to store an array or object we can use the JSON stringify methodAnd to get the data back from Redis we can use the JSON parse methodOne thing you need to remember is that data stored in Redis is stored in memory so If the machine is crashed or is shutdown the data stored in the Redis is lostTo avoid losing the data in this tutorial you will see how to use upstash which is a very popular serverless database for Redis The great thing about upstash is that it provides durable storage which means data is reloaded to memory from block storage in case of a server crash So you never lose your stored data Redis InstallationTo install Redis on your local machine you can follow the instructions from this page If you re on Mac you can install the Redis by using a single command brew install redisTo start the Redis service brew services start redisTo stop the Redis service brew services stop redisLet s create a React application to see how to use Redis Initial Project SetupCreate a new React app npx create react app serverless redis demoOnce the project is created delete all files from the src folder and create the index js App js and styles css files inside the src folder Also create components folders inside the src folder Install the required dependencies yarn add axios bootstrap dotenv ioredis react bootstrap Open the styles css file and add the following contents inside it padding margin box sizing border box body font family Segoe UI Tahoma Geneva Verdana sans serif letter spacing px background color adede container text align center margin top rem loading text align center errorMsg color ff action btn margin rem letter spacing px list list style none text align left list item border bottom px solid background color aed padding rem How to Create the Initial PagesIn this application we ll be using Star Wars API for getting a list of planets and list of people Create a new file People js inside the components folder with the following content import React from react const People people gt return lt ul className list gt people map name height gender index gt lt li className list item key index gt lt div gt Name name lt div gt lt div gt Height height lt div gt lt div gt Gender gender lt div gt lt li gt lt ul gt export default People Here we re looping over the list of people received as a prop and displaying them on the screen Note we re using the optional chaining operator so people map is the same as people amp amp people map ES has added a very useful optional chaining operator in which the next code after will be executed only if the previous reference is not undefined or null Now create a new file Planets js inside the components folder with the following content import React from react const Planets planets gt return lt ul className list gt planets map name climate terrain index gt lt li className list item key index gt lt div gt Name name lt div gt lt div gt Climate climate lt div gt lt div gt Terrain terrain lt div gt lt li gt lt ul gt export default Planets Here we re looping over the list of planets received as a prop and displaying them on the screen Now open the App js file and add the following contents inside it import React useState from react import Button from react bootstrap import axios from axios import Planets from components Planets import People from components People const App gt const result setResult useState const category setCategory useState const isLoading setIsLoading useState false const errorMsg setErrorMsg useState const getData async event gt try const name event target setCategory name setIsLoading true const data await axios url api starwars method POST data name setResult data setErrorMsg catch error setErrorMsg Something went wrong Try again later finally setIsLoading false return lt div className container gt lt div onClick getData gt lt h gt Serverless Redis Demo lt h gt lt Button variant info name planets className action btn gt Planets lt Button gt lt Button variant info name people className action btn gt People lt Button gt isLoading amp amp lt p className loading gt Loading lt p gt errorMsg amp amp lt p className errorMsg gt errorMsg lt p gt category planets lt Planets planets result gt lt People people result gt lt div gt lt div gt export default App In this file we re displaying two buttons one for planets and another for people and depending on which button is clicked we re making an API call to get either a list of planets or a list of people Note Instead of adding an onClick handler to both the buttons we ve added onClick handler for the div which contains those buttons so the code will look clean and will be beneficial If we plan to add some more buttons in the future like this lt div onClick getData gt lt div gt Inside the getData function we re using the event target name property to identify which button is clicked and then we re setting the category and loading state setCategory name setIsLoading true Then we re making an API call to the api starwars endpoint which we will create soon by passing the name as data for the API And once we ve got the result we re setting the result and errorMsg state setResult data setErrorMsg If there is any error we re setting that in catch block setErrorMsg Something went wrong Try again later And in the finally block we re setting the loading state to false setIsLoading false The finally block will always get executed even If there is success or error so we ve added the call to setIsLoading false inside it so we don t need to repeat it inside try and in the catch block we ve added a getData function which is declared as async so we can use await keyword inside it while making an API call And in the JSX depending on which category is selected by clicking on the button we re displaying the corresponding component category planets lt Planets planets result gt lt People people result gt Now open the index js file and add the following contents inside it import React from react import ReactDOM from react dom import App from App import bootstrap dist css bootstrap min css import styles css ReactDOM render lt App gt document getElementById root Now If you run the application by executing the yarn start command you ll see the following screen How to create an APINow let s create the backend API We ll use Netlify functions to create API so we don t need to create a Node js server and we can access our APIs and React application running on different ports without getting a CORS Cross Origin Resource Sharing error Netlify functions are the most popular way to create serverless applications Netlify function uses the Serverless AWS Lambda functions behind the scenes so we don t need to manage those ourselves If you re not aware of AWS Lambda functions and Netlify functions check out my this article for the introduction You can also check out my this article to understand netlify functions better Now create a new folder with the name functions inside the project folder alongside the src folder So your folder structure will look like this Inside the functions folder create a utils folder and create a new file constants js inside it and add the following contents inside it const BASE API URL module exports BASE API URL As the netlify functions and AWS Lambda functions use Node js syntax we re using the module exports for exporting the value of the constant In this file we ve defined a BASE URL for the Star Wars API Netlify Lambda functions are written like this exports handler function event context callback callback null statusCode body This is from lambda function Here we re calling the callback function by passing an object containing statusCode and body The body is always a string So If you re returning an array or object make sure to use JSON stringify method for converting the data to a string Forgetting to use JSON stringify is the most common mistake in Netlify functions Now create a starwars js file inside the functions folder with the following contents const axios require axios const BASE API URL require utils constants exports handler async event context callback gt try const name JSON parse event body const data await axios get BASE API URL name return statusCode body JSON stringify data results catch error return statusCode body JSON stringify Something went wrong Try again later In this file initially we re parsing the request data using the JSON parse method const name JSON parse event body We re accessing name from body because If you remember from the App js file of our React app we re making API call like this const data await axios url api starwars method POST data name So we re passing name as data for the API As we ve created the netlify function in starwars js file inside the functions folder Netlify will create the function with the same name of the file so we re able to access the API using api starwars URL Here we re passing the value contained in the name property as data for the request sodata name is the same asdata name name If the key and the variable containing value are the same then using ES shorthand syntax we can skip the colon and the variable name Therefore we re using the JSON parse method to destructure the name property from the event body object Then inside the starwars js file we re making an API call to the actual star wars API const data await axios get BASE API URL name The axios response comes in the data property so we re destructuring it so the above code is the same as the below code const response await axios get BASE API URL name const data response data If you check Star Wars Planets People API you ll see that the actual data of the API is stored in the results property of the response Therefore once we have the response we re returning the data results back to the client Our React App return statusCode body JSON stringify data results If there s an error we re returning back the error message return statusCode body JSON stringify Something went wrong Try again later How to execute the Netlify functionsTo Inform the netlify that we want to execute the netlify functions create a new file netlify toml inside the serverless redis demo project folder with the following content build command CI yarn run build publish build functions functions redirects from api to netlify functions splat status force trueThis is the configuration file for Netlify where we specify the build configuration Let s break it down The command specifies the command that needs to be executed to create a production build folderThe CI is specific to Netify so netlify does not throw errors while deploying the applicationThe publish specifies the name of the folder to be used for deploying the applicationThe functions specifies the name of the folder where all our Serverless functions are storedAll the serverless functions when deployed to the Netlify are accessible at the URL netlify functions so instead of specifying the complete path every time while making an API call we instruct Netlify that whenever any request comes for api function name redirect it to netlify functions function name splat specifies that whatever comes after api should be used after netlify functions So when we call api starwars API behind the scenes the netlify functions starwars path will be used To execute the netlify functions we need to install the netlify cli npm library which will run our serverless functions and also our React app Install the library by executing the following command from the terminal npm install netlify cli gIf you re on Linux Mac then you might need to add a sudo before it to install it globally sudo npm install netlify cli gNow start the application by running the following command from the terminal from inside the serverless redis demo project folder netlify devThe netlify dev command will first run our serverless functions from the functions folder and then our React application and it will automatically manage the proxy so you will not get a CORS error while accessing the serverless functions from the React application Now navigate to http localhost and check the applicationAs you can see clicking on the buttons correctly fetches data from the API As we re not using Redis yet you ll see that every time we click on any of the buttons we re making a fresh API call to the Star Wars API So to get the result back it takes some time and till that time we re seeing the loading message As you can see the API call is taking more than milliseconds to get the result from the API So suppose If you re accessing data from the database and the response contains a lot of data then it might take more time to get the response back So let s use Redis now to reduce the API response time Using Redis In The ApplicationWe ll use the ioredis which is a very popular Redis client for Node js As you can see above this library has around Million weekly downloads Now open the functions starwars js file and replace it with the following contents const axios require axios require dotenv config const BASE API URL require utils constants const Redis require ioredis const redis new Redis process env DB CONNECTION URL exports handler async event context callback gt try const name JSON parse event body const cachedResult await redis get name if cachedResult console log returning cached data return statusCode body JSON stringify JSON parse cachedResult const data await axios get BASE API URL name redis set name JSON stringify data results EX console log returning fresh data return statusCode body JSON stringify data results catch error return statusCode body JSON stringify Something went wrong Try again later Here we ve some initial imports at the top of the file const axios require axios require dotenv config const BASE API URL require utils constants const Redis require ioredis As we re using ioredis npm library we ve imported it and then we re creating an object of Redis by passing it a connection string const redis new Redis process env DB CONNECTION URL Here for the Redis constructor function we re passing the connection URL to access data store somewhere else If we don t pass any argument to the constructor then the locally installed Redis database will be used Also instead of directly providing the connection URL we re using environment variable for security reasons You should always use environment variables for API Keys or database connection URLs or password to make it secure Configuring upstash Redis DatabaseTo get the actual connection URL value navigate to upstash and log in with either google GitHub or Amazon account Once logged in you ll see the following screen Click on the CREATE DATABASE button and enter the database details and click on the CREATE button Once the database is created you ll see the following screen Click on the REDIS CONNECT button and then select the Node js ioredis from the dropdown and copy the connection URL value Now create a new env file inside the serverless redis demo folder and add the following contents inside it DB CONNECTION URL your copied connection urlYou should never push env file to GitHub repository so make sure to include the env file in the gitignore file so it will not be pushed to GitHub repository Now let s proceed with understanding the code from the functions starwars js file Once we have the connection URL we re creating a Redis object using const redis new Redis process env DB CONNECTION URL Then we ve defined the netlify function as shown below exports handler async event context callback gt try const name JSON parse event body const cachedResult await redis get name if cachedResult console log returning cached data return statusCode body JSON stringify JSON parse cachedResult const data await axios get BASE API URL name redis set name JSON stringify data results EX console log returning fresh data return statusCode body JSON stringify data results catch error return statusCode body JSON stringify Something went wrong Try again later Inside the function we re accessing the name value from the request data and then we re calling the get method of the Redis object const cachedResult await redis get name As Redis database stores data as a key value pair To get the data for the provided key we use the redis get method as shown above So If the name is planets then the key will be planets If there is no such key in the Redis then Redis will return null So next we re checking If the key exists If yes then we re returning the data back from the function if cachedResult console log returning cached data return statusCode body JSON stringify JSON parse cachedResult We ve also added a console log so we can see If we re getting cached result or fresh result If no such key exists then we re making the API call to the Star Wars API using axios Then we re storing the response data in the Redis database using the set method For the set method we re passing the key the response data in a stringified format EX constant to specify expiry time and the value to expire the redis key value pair after secondsconst data await axios get BASE API URL name redis set name JSON stringify data results EX The Redis maintains its own timer so If the seconds are over after setting the value Redis will remove the key value pair So the next time we call this function and seconds are not over after setting the key value pair then we ll get the cached data so there is no need of making an API call again Then we re returning that data from the function console log returning fresh data return statusCode body JSON stringify data results Verifying the Caching FunctionalityNow we ve added the caching functionality let s verify the functionality of the application As you can see when we click on the planets button the first time it takes some time to get the API response But after every next click it takes less time to get the response This is because for every button click after the first click we re always returning the cached response which we got when we clicked the button the first time which we can confirm from the log printed in the console Also If you remember once we got the response we re setting an expiry time of seconds for the Redis data in the functions starwars js file redis set name JSON stringify data results EX So after every seconds from getting the response the Redis data is removed so we always get fresh data after seconds As you can see once we got the response we re starting the timer and once seconds are over we re again clicking on the button to make another API call As seconds are over the Redis data is removed so we again get fresh data as can be confirmed from the returning fresh data log in the console and next time we again click on the button before the seconds are over we re getting cached data instead of fresh data The caching functionality will work the same when we click on the People button to get a list of people Using Local Installation of RedisAs we have seen to connect to the Upstash redis database we re passing connection URL to the Redis constructor functions starwars jsconst redis new Redis process env DB CONNECTION URL If we don t pass any argument to the constructor like this const redis new Redis then the locally installed Redis database will be used So let s see how that works If Redis is already installed on your machine then to access the Redis through the command line we can execute the redis cli command Check out the below video to see it in action As you can see in the above video to get the data stored at key people we re using the following Redis command get peopleHere we re using people because we ve used people as the name of the key while saving to Redis using redis set methodInitially it does not exist so nil is returned which is equivalent to null in JavaScript Then once we click on the People button to get the list of people the people key gets set so we get the data back If we again execute the get people commandAs we ve set the expiry time as seconds the key value pair is deleted once seconds timeout is overso we re using ttl time to live command to get the remaining time of the key expiry in seconds like this ttl peopleIf the value returned by ttl is then it means that the key does not exist as it s expiredIf the value returned by ttl is then it means that the key will never expire which will be the case If we don t specify the expiry while using the redis set method So if the ttl is the application will make the API call again and will not return the cached data as the key is expired so again you will see a loading message for some more time That s it about this tutorial You can find the complete source code for this tutorial in this repository ConclusionAs we have seen using Redis to return cached data can make the application load faster which is very important when we either have a lot of data in the response or the backend takes time to send the response or we re making an API call to get data from the database Also with Redis after the specified amount of expiry time we can make a new API call to get updated data instead of returning cached data As Redis data is stored in memory data might get lost If the machine is crashed or shut down so we can use the upstash as a serverless database so the data will never get lost even If the machine is crashed |
2021-07-07 05:48:06 |
医療系 |
医療介護 CBnews |
次期診療報酬改定へ、9月ごろ論点の意見整理-中医協 |
https://www.cbnews.jp/news/entry/20210707142657
|
中央社会保険医療協議会 |
2021-07-07 14:45:00 |
医療系 |
医療介護 CBnews |
8月からの制度改正で事務処理など通知-厚労省 |
https://www.cbnews.jp/news/entry/20210707133524
|
介護保険 |
2021-07-07 14:40:00 |
金融 |
日本銀行:RSS |
コール市場残高(6月) |
http://www.boj.or.jp/statistics/market/short/call/call.xlsx
|
残高 |
2021-07-07 15:00:00 |
ニュース |
BBC News - Home |
Covid: Heathrow to trial fast-tracking vaccinated arrivals |
https://www.bbc.co.uk/news/business-57743038
|
pilot |
2021-07-07 05:51:21 |
ニュース |
BBC News - Home |
Peter R de Vries: Dutch crime journalist wounded in Amsterdam shooting |
https://www.bbc.co.uk/news/world-europe-57743233
|
amsterdam |
2021-07-07 05:55:44 |
ニュース |
BBC News - Home |
Newspaper headlines: 'Isolation insanity' and 'Beer we go' as England awaits |
https://www.bbc.co.uk/news/blogs-the-papers-57744001
|
Newspaper headlines x Isolation insanity x and x Beer we go x as England awaitsThe papers consider the risks of extending isolation rules for the fully vaccinated as Euros fever builds |
2021-07-07 05:04:39 |
ニュース |
BBC News - Home |
'Have no fear' - former England semi-finalists' advice for the current team |
https://www.bbc.co.uk/sport/football/57732771
|
england |
2021-07-07 05:19:41 |
ニュース |
BBC News - Home |
Euro 2020: England manager Gareth Southgate says he is only focused on semi-final against Denmark |
https://www.bbc.co.uk/sport/av/football/57742510
|
Euro England manager Gareth Southgate says he is only focused on semi final against DenmarkEngland manager Gareth Southgate tells BBC Radio Live s Emma Saunders he is solely focused on the semi final against Denmark |
2021-07-07 05:27:59 |
ニュース |
BBC News - Home |
England v Denmark: Who made your England XI for semi-final against Denmark? |
https://www.bbc.co.uk/sport/football/57713107
|
denmark |
2021-07-07 05:16:19 |
GCP |
Google Cloud Platform Japan 公式ブログ |
Mrs. T’s Pierogies: Google Cloud での SAP の活用により予測と DR の能力を改善 |
https://cloud.google.com/blog/ja/products/sap-google-cloud/mrs-ts-migrates-sap-ecc-to-s4hana-on-google-cloud/
|
また、GoogleCloudでのSAPを実行することにより、同社がSAPデータに求めていた高速でフレキシブルな分析機能が実現できることも認識していました。 |
2021-07-07 06:00:00 |
ビジネス |
東洋経済オンライン |
「話す、聞く」を重視し過ぎる英語習得の落とし穴 英語は「話せないけど読める」という人の大誤解 | 英語学習 | 東洋経済オンライン |
https://toyokeizai.net/articles/-/437513?utm_source=rss&utm_medium=http&utm_campaign=link_back
|
東洋経済オンライン |
2021-07-07 14:30:00 |
ニュース |
Newsweek |
世界で最低レベルの、日本の教員の院卒比率 |
https://www.newsweekjapan.jp/stories/world/2021/07/post-96653.php
|
|
2021-07-07 14:45:00 |
ビジネス |
プレジデントオンライン |
自分を「戦力」だと思えたのは、殺し合いの場――『バトルグラウンドワーカーズ』第6話 - 『バトルグラウンドワーカーズ』 |
https://president.jp/articles/-/47180
|
殺し合い |
2021-07-07 15:00:00 |
IT |
週刊アスキー |
8月上旬までの期間限定! 横浜DeNAの佐野選手が選んだブレンドコーヒー「SANO BLEND」販売中 |
https://weekly.ascii.jp/elem/000/004/061/4061850/
|
coffeeandbeer |
2021-07-07 14:50:00 |
IT |
週刊アスキー |
新作対戦格闘ゲーム『KOF XV』がマルチプラットフォームで2022年春に発売決定! |
https://weekly.ascii.jp/elem/000/004/061/4061852/
|
kofxv |
2021-07-07 14:50:00 |
IT |
週刊アスキー |
最後の問題まで解けるかな? 横浜市保土ヶ谷区で謎解きイベント「なぞ解き!ほどがやアドベンチャー」を開催中 |
https://weekly.ascii.jp/elem/000/004/061/4061849/
|
保土ヶ谷区 |
2021-07-07 14:40:00 |
IT |
週刊アスキー |
動物デザインのシールが可愛すぎる! 金沢動物園を含む3動物園「へんしん!どうぶつマスク」を先行販売 |
https://weekly.ascii.jp/elem/000/004/061/4061832/
|
先行販売 |
2021-07-07 14:30:00 |
IT |
週刊アスキー |
有機ELモデルの新型Nintendo Switchが10月8日に発売決定!従来モデルとの違いとは? |
https://weekly.ascii.jp/elem/000/004/061/4061834/
|
nintendo |
2021-07-07 14:30:00 |
IT |
週刊アスキー |
100本限定! ジェットストリーム4&1多機能ペンなど購入で名入れ彫刻が無料、ヨドバシカメラ 新宿西口本店にて実演販売 |
https://weekly.ascii.jp/elem/000/004/061/4061829/
|
実演販売 |
2021-07-07 14:10:00 |
IT |
週刊アスキー |
横浜に実在した伝説の娼婦を描く 五大路子さんのひとり芝居「『横浜ローザ』赤い靴の娼婦の伝説」、神奈川芸術劇場で8月12日から |
https://weekly.ascii.jp/elem/000/004/061/4061833/
|
五大路子 |
2021-07-07 14:10:00 |
マーケティング |
AdverTimes |
安西水丸がデザインした広告などのポスター25点を展示 |
https://www.advertimes.com/20210707/article357403/
|
三軒茶屋 |
2021-07-07 05:30:34 |
マーケティング |
AdverTimes |
勝手に作った1枚のポスターから、クリエイティブキャリアが始まった【前編】 |
https://www.advertimes.com/20210707/article357107/
|
養成 |
2021-07-07 05:00:51 |
GCP |
Cloud Blog JA |
Mrs. T’s Pierogies: Google Cloud での SAP の活用により予測と DR の能力を改善 |
https://cloud.google.com/blog/ja/products/sap-google-cloud/mrs-ts-migrates-sap-ecc-to-s4hana-on-google-cloud/
|
また、GoogleCloudでのSAPを実行することにより、同社がSAPデータに求めていた高速でフレキシブルな分析機能が実現できることも認識していました。 |
2021-07-07 06:00:00 |
コメント
コメントを投稿