Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions examples/google-cloud-functions-with-typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Google Cloud Functions Example with Typescript

## How to use

1. Clone and install the example

```bash
git clone https://github.com/upstash/upstash-redis.git
cd upstash-redis/examples/google-cloud-functions
npm install
```

2. Create a free Database on [upstash.com](https://console.upstash.com/redis)
3. Copy the `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` to
`Runtime, build, connections and security settings > Runtime environment variables` in GCP website when creating a new function or pass those keys when you are deploying from the CLI.


## Work locally

Simply run `npm run start`
19 changes: 19 additions & 0 deletions examples/google-cloud-functions-with-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "google-cloud-functions-typescript",
"version": "1.0.0",
"description": "@upstash-redis example using Google cloud functions with Typescript",
"main": "dist/index.js",
"scripts": {
"start": "npx tsc-watch --onSuccess 'npx @google-cloud/functions-framework --target=helloWorld'",
"build": "npx tsc"
},
"dependencies": {
"@google-cloud/functions-framework": "^3.3.0",
"typescript": "^5.2.2"
},
"devDependencies": {
"@types/node": "^20.7.0",
"ts-node": "^10.9.1",
"tsc-watch": "^6.0.4"
}
}
17 changes: 17 additions & 0 deletions examples/google-cloud-functions-with-typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import functions = require("@google-cloud/functions-framework");
import { Redis } from "@upstash/redis/with-fetch";

functions.http("helloWorld", async (_req, res) => {
const redis = Redis.fromEnv();

const set = await redis.set("rng", Math.random());
const get = await redis.get("rng");

res.send({
statusCode: 200,
body: JSON.stringify({
set,
get,
}),
});
});
8 changes: 8 additions & 0 deletions examples/google-cloud-functions-with-typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"module": "commonjs",
"outDir": "dist"
},
"include": ["src/**/*.ts"],
"exclude": ["./node_modules/", "./dist/"]
}
20 changes: 20 additions & 0 deletions examples/google-cloud-functions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Google Cloud Functions Example

## How to use

1. Clone and install the example

```bash
git clone https://github.com/upstash/upstash-redis.git
cd upstash-redis/examples/google-cloud-functions
npm install
```

2. Create a free Database on [upstash.com](https://console.upstash.com/redis)
3. Copy the `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` to
`Runtime, build, connections and security settings > Runtime environment variables` in GCP when creating a new function or pass those keys when you are deploying from the CLI.


## Work locally

Simply run `npm run start`
17 changes: 17 additions & 0 deletions examples/google-cloud-functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const functions = require("@google-cloud/functions-framework");
const { Redis } = require("@upstash/redis/with-fetch");

functions.http("helloWorld", async (_req, res) => {
const redis = Redis.fromEnv();

const set = await redis.set("rng", Math.random());
const get = await redis.get("rng");

res.send({
statusCode: 200,
body: JSON.stringify({
set,
get,
}),
});
});
9 changes: 9 additions & 0 deletions examples/google-cloud-functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"@google-cloud/functions-framework": "^3.3.0",
"@upstash/redis": "^1.23.3"
},
"scripts": {
"start": "npx @google-cloud/functions-framework --target=helloWorld"
}
}