Skip to content

Commit

Permalink
removed callback support (#11)
Browse files Browse the repository at this point in the history
* running tests from dist folder

* refactor

* fix: test script

* remove auto fill

* fix filter arguments

* fix test

* fix: readme

* fix: then test and readme example

* fix auto fill env variables

* fix export

* update version
  • Loading branch information
ademilter authored Nov 11, 2021
1 parent 5593a18 commit 21a06e8
Show file tree
Hide file tree
Showing 131 changed files with 1,114 additions and 2,781 deletions.
43 changes: 13 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,58 +26,41 @@ See [the list of APIs](https://docs.upstash.com/features/restapi#rest---redis-ap
npm install @upstash/redis
```

### Usage with Callback Style
### Usage with Promise

```typescript
import upstash from '@upstash/redis';
import { auth, set } from '@upstash/redis';

const redis = upstash('UPSTASH_REDIS_REST_URL', 'UPSTASH_REDIS_REST_TOKEN');
auth('UPSTASH_REDIS_REST_URL', 'UPSTASH_REDIS_REST_TOKEN');

redis.get('key', function ({ data, error }) {
if (error) {
return console.error(error);
}
set('key', 'value').then(({ data }) => {
console.log(data);
// -> "OK"
});
```

### Usage with async/await (Promise)
### Usage with async/await

```typescript
import upstash from '@upstash/redis';

const redis = upstash('UPSTASH_REDIS_REST_URL', 'UPSTASH_REDIS_REST_TOKEN');
import { set } from '@upstash/redis';

(async () => {
try {
const { data, error } = await redis.get('key');
const { data, error } = await set('key', 'value');
if (error) throw error;
console.log(data);
// -> "OK"
} catch (error) {
console.error(error);
}
})();
```

If you define `UPSTASH_REDIS_REST_URL` and` UPSTASH_REDIS_REST_TOKEN` environment variables, you can run the Redis commands directly.

```typescript
import { get } from '@upstash/redis';

(async () => {
try {
const { data, error } = await get('key');
if (error) throw error;
console.log(data);
} catch (error) {
console.error(error);
}
})();
```
> If you define `UPSTASH_REDIS_REST_URL` and` UPSTASH_REDIS_REST_TOKEN` environment variables, you can run the Redis commands directly.
### Edge Support

Once you set `edgeUrl`, all read commands are fetched using edge url. The REST URL is used for write/update commands.
Once you set `edgeUrl`, all read commands are fetched using edge url. The REST URL is used for write/update commands.

```typescript
import upstash from '@upstash/redis';
Expand All @@ -97,9 +80,9 @@ const redis = upstash({
// -> null | string
console.log(metadata);
// -> { edge: boolean, cache: null | 'miss' | 'hit' }

// the below reads using REST url (non-edge)
const get1 = await redis.get('key', {edge: false});
const get1 = await redis.get('key', { edge: false });
if (get1.error) throw get1.error;
} catch (error) {
console.error(error);
Expand Down
3 changes: 3 additions & 0 deletions examples/nodejs/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=
UPSTASH_REDIS_EDGE_URL=
18 changes: 18 additions & 0 deletions examples/nodejs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import dotenv from 'dotenv';
import upstash from '@upstash/redis';

dotenv.config();

const redis = upstash.default({
url: process.env.UPSTASH_REDIS_REST_URL,
token: process.env.UPSTASH_REDIS_REST_TOKEN,
edgeUrl: process.env.UPSTASH_REDIS_EDGE_URL,
});

(async function run() {
const res1 = await redis.set('node', '23');
console.log(res1);

const res2 = await redis.get('node');
console.log(res2);
})();
11 changes: 11 additions & 0 deletions examples/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "nodejs",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@upstash/redis": "../../",
"dotenv": "^10.0.0"
}
}
51 changes: 51 additions & 0 deletions examples/nodejs/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@upstash/redis@../../":
version "0.1.22"
dependencies:
isomorphic-unfetch "^3.1.0"

dotenv@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==

isomorphic-unfetch@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/isomorphic-unfetch/-/isomorphic-unfetch-3.1.0.tgz#87341d5f4f7b63843d468438128cb087b7c3e98f"
integrity sha512-geDJjpoZ8N0kWexiwkX8F9NkTsXhetLPVbZFQ+JTW239QNOwvB0gniuR1Wc6f0AMTn7/mFGyXvHTifrCp/GH8Q==
dependencies:
node-fetch "^2.6.1"
unfetch "^4.2.0"

node-fetch@^2.6.1:
version "2.6.6"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.6.tgz#1751a7c01834e8e1697758732e9efb6eeadfaf89"
integrity sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==
dependencies:
whatwg-url "^5.0.0"

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=

unfetch@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-4.2.0.tgz#7e21b0ef7d363d8d9af0fb929a5555f6ef97a3be"
integrity sha512-F9p7yYCn6cIW9El1zi0HI6vqpeIvBsr3dSuRO6Xuppb1u5rXpCPmMvLSyECLhybr9isec8Ohl0hPekMVrEinDA==

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@upstash/redis",
"version": "0.1.22",
"version": "0.1.3",
"description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
"author": "Adem ilter <[email protected]>",
"license": "MIT",
"main": "dist/main/src/index.js",
"types": "dist/main/src/index.d.ts",
"module": "dist/module/src/index.js",
"main": "dist/main/index.js",
"types": "dist/main/index.d.ts",
"module": "dist/module/index.js",
"jsdelivr": "dist/umd/upstash-redis.js",
"unpkg": "dist/umd/upstash-redis.js",
"scripts": {
Expand Down Expand Up @@ -41,16 +41,16 @@
},
"size-limit": [
{
"path": "dist/main/src/index.js",
"limit": "6 KB"
"path": "dist/main/index.js",
"limit": "5 KB"
},
{
"path": "dist/module/src/index.js",
"limit": "6 KB"
"path": "dist/module/index.js",
"limit": "5 KB"
},
{
"path": "dist/umd/upstash-redis.js",
"limit": "6 KB"
"limit": "5 KB"
}
],
"prettier": {
Expand Down
Loading

0 comments on commit 21a06e8

Please sign in to comment.