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
Show all changes
23 commits
Select commit Hold shift + click to select a range
0844d3c
fix: vercel edge runs again
chronark May 6, 2022
4aba9ec
chore: move files
chronark May 6, 2022
345cedf
Merge branch 'main' of github.com:upstash/upstash-redis into serializ…
chronark May 6, 2022
f76a978
docs
chronark May 6, 2022
876e575
Merge branch 'main' of github.com:upstash/upstash-redis
chronark May 6, 2022
aee7684
Merge branch 'main' of github.com:upstash/upstash-redis
chronark May 9, 2022
19439c8
feat: export types
chronark May 12, 2022
121661f
Merge branch 'main' of github.com:upstash/upstash-redis
chronark May 16, 2022
94d4a5a
v1.4.0 (#91)
chronark May 23, 2022
a44ab07
chore: merge
chronark May 23, 2022
51012b5
Merge branch 'main' of github.com:upstash/upstash-redis
chronark May 23, 2022
6e00ba9
Merge branch 'main' of github.com:upstash/upstash-redis into release
chronark May 23, 2022
e00198e
Merge branch 'release'
chronark May 23, 2022
0e09b94
Merge branch 'main' of github.com:upstash/upstash-redis
chronark May 23, 2022
8021c2d
Merge branch 'main' of github.com:upstash/upstash-redis
chronark May 24, 2022
22576e5
Merge branch 'main' of github.com:upstash/upstash-redis
chronark May 30, 2022
c08ae94
Merge branch 'main' of github.com:upstash/upstash-redis
chronark May 31, 2022
66f706f
style: fmt
chronark May 31, 2022
c9c6a9f
feat: cloudflare typescript example
chronark May 31, 2022
ad92bbd
ci: add needs
chronark May 31, 2022
a717986
ci: use start command
chronark May 31, 2022
1c51235
ci: use start command
chronark May 31, 2022
e1dbb41
docs: add example in readme
chronark May 31, 2022
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
130 changes: 105 additions & 25 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ on:
- cron: "0 0 * * *" # daily

jobs:



test:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -74,7 +71,6 @@ jobs:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x


- uses: pnpm/action-setup@v2
with:
Expand Down Expand Up @@ -129,7 +125,6 @@ jobs:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x


- uses: pnpm/action-setup@v2
with:
Expand Down Expand Up @@ -242,7 +237,6 @@ jobs:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x


- uses: pnpm/action-setup@v2
with:
Expand Down Expand Up @@ -291,12 +285,11 @@ jobs:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- uses: pnpm/action-setup@v2
with:
version: 6


- name: Install example
run: |
pnpm add @upstash/redis@${{needs.release.outputs.version}}
Expand All @@ -315,8 +308,6 @@ jobs:
env:
DEPLOYMENT_URL: https://upstash-redis-with-wrangler-1.upstash.workers.dev



cloudflare-workers-local:
needs:
- test
Expand All @@ -330,7 +321,6 @@ jobs:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x


- uses: pnpm/action-setup@v2
with:
Expand All @@ -348,15 +338,17 @@ jobs:
REDIS_SERVER_CONFIG: ${{ secrets.REDIS_SERVER_CONFIG }}

- name: Install example
run: pnpm add @upstash/redis@../../dist
run: |
pnpm add @upstash/redis@../../dist
pnpm add -g wrangler
working-directory: examples/cloudflare-workers

- name: Add account ID
run: echo 'account_id = "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"' >> wrangler.toml
working-directory: examples/cloudflare-workers

- name: Start example
run: pnpm dev & sleep 5
run: wrangler dev & sleep 5
working-directory: examples/cloudflare-workers
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
Expand All @@ -383,24 +375,23 @@ jobs:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- uses: pnpm/action-setup@v2
with:
version: 6



- name: Install example
run: |
pnpm add @upstash/redis@${{needs.release.outputs.version}}
pnpm add -g wrangler
working-directory: examples/cloudflare-workers

- name: Add account ID
run: echo 'account_id = "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"' >> wrangler.toml
working-directory: examples/cloudflare-workers

- name: Deploy
run: pnpm deploy
run: wrangler publish
working-directory: examples/cloudflare-workers
env:
CLOUDFLARE_API_TOKEN: ${{secrets.CF_API_TOKEN}}
Expand All @@ -411,6 +402,98 @@ jobs:
env:
DEPLOYMENT_URL: https://upstash-redis.upstash.workers.dev

cloudflare-workers-with-typescript-local:
needs:
- test
env:
UPSTASH_REDIS_REST_URL: http://127.0.0.1:6379
UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_AUTH_TOKEN }}
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v2
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- uses: pnpm/action-setup@v2
with:
version: 6

- name: Build
run: deno run -A ./cmd/build.ts

- name: Start redis server
uses: ./.github/actions/redis
with:
UPSTASH_REDIS_REST_URL: http://127.0.0.1:6379
UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_AUTH_TOKEN }}
UPSTASH_REPO_ACCESS_TOKEN: ${{ secrets.UPSTASH_REPO_ACCESS_TOKEN }}
REDIS_SERVER_CONFIG: ${{ secrets.REDIS_SERVER_CONFIG }}

- name: Install example
run: |
pnpm add @upstash/redis@../../dist
pnpm add -g wrangler

working-directory: examples/cloudflare-workers-with-typescript

- name: Add account ID
run: echo 'account_id = "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"' >> wrangler.toml
working-directory: examples/cloudflare-workers-with-typescript

- name: Start example
run: wrangler dev & sleep 5
working-directory: examples/cloudflare-workers-with-typescript
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}

- name: Test
run: deno test -A ./test.ts
working-directory: examples/cloudflare-workers-with-typescript
env:
DEPLOYMENT_URL: http://localhost:8787

cloudflare-workers-with-typescript-deployed:
needs:
- release
env:
UPSTASH_REDIS_REST_URL: http://127.0.0.1:6379
UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_AUTH_TOKEN }}
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v2
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- uses: pnpm/action-setup@v2
with:
version: 6

- name: Install example
run: |
pnpm add @upstash/redis@${{needs.release.outputs.version}}
pnpm add -g wrangler
working-directory: examples/cloudflare-workers-with-typescript

- name: Add account ID
run: echo 'account_id = "${{ secrets.CLOUDFLARE_ACCOUNT_ID }}"' >> wrangler.toml
working-directory: examples/cloudflare-workers-with-typescript

- name: Deploy
run: wrangler publish
working-directory: examples/cloudflare-workers-with-typescript
env:
CLOUDFLARE_API_TOKEN: ${{secrets.CF_API_TOKEN}}

- name: Test
run: deno test -A ./test.ts
working-directory: examples/cloudflare-workers-with-typescript
env:
DEPLOYMENT_URL: https://cloudflare-workers-with-typescript.upstash.workers.dev

fastly-local:
needs:
- test
Expand All @@ -424,7 +507,7 @@ jobs:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- uses: pnpm/action-setup@v2
with:
version: 6
Expand Down Expand Up @@ -491,8 +574,6 @@ jobs:
with:
version: 6



- name: Install example
working-directory: ./examples/fastly
run: |
Expand Down Expand Up @@ -580,7 +661,7 @@ jobs:
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- uses: pnpm/action-setup@v2
with:
version: 6
Expand All @@ -604,8 +685,6 @@ jobs:
run: node ./index.js
working-directory: examples/nodejs-18



release:
outputs:
version: ${{ steps.version.outputs.version }}
Expand All @@ -616,6 +695,7 @@ jobs:
- nextjs-local
- nextjs-edge-local
- cloudflare-workers-with-wrangler-1-local
- cloudflare-workers-with-typescript-local
- cloudflare-workers-local

name: Release
Expand All @@ -625,7 +705,7 @@ jobs:
uses: actions/checkout@v2

- name: Get version
id: version
id: version
run: echo "::set-output name=version::v0.0.0-ci.${GITHUB_SHA::8}"

- name: Setup Node
Expand All @@ -644,4 +724,4 @@ jobs:
working-directory: ./dist
run: |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > .npmrc
npm publish --access public --tag=ci
npm publish --access public --tag=ci
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export default {
}
```

- [Code example Wrangler 2](https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers)
- [Code example](https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers)
- [Code example typescript](https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers-with-typescript)
- [Code example Wrangler 1](https://github.com/upstash/upstash-redis/tree/main/examples/cloudflare-workers-with-wrangler-1)
- [Documentation](https://docs.upstash.com/redis/tutorials/cloudflare_workers_with_redis)

Expand Down
26 changes: 26 additions & 0 deletions examples/cloudflare-workers-with-typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Cloudflare Worker Typescript Example

This example uses
[Wrangler](https://developers.cloudflare.com/workers/wrangler/) to create a
typescript worker

## How to use

1. Clone and install the example

```bash
git clone https://github.com/upstash/upstash-redis.git
cd upstash-redis/examples/cloudflare-workers-with-typescript
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
`wrangler.toml`
4. Start the development server

```bash
npm run start
```

5. Open your browser at [localhost:8787](http://localhost:8787)
17 changes: 17 additions & 0 deletions examples/cloudflare-workers-with-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "cloudflare-workers-with-typescript",
"version": "0.0.0",
"devDependencies": {
"@cloudflare/workers-types": "^3.11.0",
"typescript": "^4.7.2",
"wrangler": "2.0.7"
},
"private": true,
"scripts": {
"start": "wrangler dev",
"publish": "wrangler publish"
},
"dependencies": {
"@upstash/redis": "latest"
}
}
20 changes: 20 additions & 0 deletions examples/cloudflare-workers-with-typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Redis } from "@upstash/redis/cloudflare";

export interface Env {
UPSTASH_REDIS_REST_URL: string;
UPSTASH_REDIS_REST_TOKEN: string;
}

export default {
async fetch(
_request: Request,
env: Env,
_ctx: ExecutionContext,
): Promise<Response> {
const redis = Redis.fromEnv(env);

const count = await redis.incr("cloudflare-workers-with-typescript-count");

return new Response(JSON.stringify({ count }));
},
};
18 changes: 18 additions & 0 deletions examples/cloudflare-workers-with-typescript/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

const deploymentURL = Deno.env.get("DEPLOYMENT_URL");
if (!deploymentURL) {
throw new Error("DEPLOYMENT_URL not set");
}

Deno.test("works", async () => {
console.log({ deploymentURL });
const url = `${deploymentURL}/`;
const res = await fetch(url);
if (res.status !== 200) {
console.log(await res.text());
}
assertEquals(res.status, 200);
const json = (await res.json()) as { count: number };
assertEquals(typeof json.count, "number");
});
Loading