Skip to content

Commit

Permalink
docs: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 16, 2021
1 parent 247e462 commit e898032
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 47 deletions.
2 changes: 1 addition & 1 deletion packages/memoize/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Install

```shell
npm install --save keyv @keyvhq/memoize
npm install --save @keyvhq/memoize
```

## Usage
Expand Down
21 changes: 15 additions & 6 deletions packages/mongo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,33 @@ Uses TTL indexes to automatically remove expired documents. However [MongoDB doe
## Install

```shell
npm install --save keyv @keyvhq/mongo
npm install --save @keyvhq/core @keyvhq/mongo
```

## Usage

```js
const KeyvMongo = require('@keyvhq/mongo')
const Keyv = require('@keyvhq/core')

const keyv = new Keyv('mongodb://user:pass@localhost:27017/dbname')
const keyv = new Keyv({
store: new KeyvMongo('mongodb://user:pass@localhost:27017/dbname')
})

keyv.on('error', handleConnectionError)
```

You can specify the collection name, by default `'keyv'` is used.

e.g:
You can specify the collection name, by default `'keyv'` is used:

```js
const keyv = new Keyv('mongodb://user:pass@localhost:27017/dbname', { collection: 'cache' })
const KeyvMongo = require('@keyvhq/mongo')
const Keyv = require('@keyvhq/core')

const keyv = new Keyv({
store: new KeyvMongo('mongodb://user:pass@localhost:27017/dbname', {
collection: 'cache'
})
})
```

## License
Expand Down
2 changes: 1 addition & 1 deletion packages/multi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Install

```shell
npm install --save keyv @keyvhq/multi
npm install --save @keyvhq/multi
```

## Usage
Expand Down
23 changes: 15 additions & 8 deletions packages/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,33 @@
## Install

```shell
npm install --save keyv @keyvhq/mysql
npm install --save @keyvhq/core @keyvhq/mysql
```

## Usage

```js
const KeyvMysql = require('@keyvhq/redis')
const Keyv = require('@keyvhq/core')

const keyv = new Keyv('mysql://user:pass@localhost:3306/dbname')
const keyv = new Keyv({
store: new KeyvMysql('mysql://user:pass@localhost:3306/dbname')
})

keyv.on('error', handleConnectionError)
```

You can specify a custom table with the `table` option and the primary key size with `keySize`.

e.g:
You can specify a custom table with the `table` option and the primary key size with `keySize`:

```js
const keyv = new Keyv('mysql://user:pass@localhost:3306/dbname', {
table: 'cache',
keySize: 255
const KeyvMysql = require('@keyvhq/redis')
const Keyv = require('@keyvhq/core')

const keyv = new Keyv({
store: new KeyvMysql('mysql://user:pass@localhost:3306/dbname', {
table: 'cache',
keySize: 255
})
})
```

Expand Down
21 changes: 15 additions & 6 deletions packages/postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,33 @@ Requires Postgres 9.5 or newer for `ON CONFLICT` support to allow performant ups
## Install

```shell
npm install --save keyv @keyvhq/postgres
npm install --save @keyvhq/core @keyvhq/postgres
```

## Usage

```js
const KeyvPostgres = require('@keyvhq/postgres')
const Keyv = require('@keyvhq/core')

const keyv = new Keyv('postgresql://user:pass@localhost:5432/dbname')
const keyv = new Keyv({
store: new KeyvPostgres('postgresql://user:pass@localhost:5432/dbname')
})

keyv.on('error', handleConnectionError)
```

You can specify the `table` option.

e.g:
You can specify the `table` option:

```js
const keyv = new Keyv('postgresql://user:pass@localhost:5432/dbname', { table: 'cache' })
const KeyvPostgres = require('@keyvhq/postgres')
const Keyv = require('@keyvhq/core')

const keyv = new Keyv({
store: new KeyvPostgres('postgresql://user:pass@localhost:5432/dbname', {
table: 'cache'
})
})
```

## License
Expand Down
30 changes: 14 additions & 16 deletions packages/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,44 @@ TTL functionality is handled directly by Redis so no timestamps are stored and e
## Install

```shell
npm install --save keyv @keyvhq/redis
npm install --save @keyvhq/core @keyvhq/redis
```

## Usage

```js
const KeyvRedis = require('@keyvhq/redis')
const Keyv = require('@keyvhq/core')

const keyv = new Keyv('redis://user:pass@localhost:6379')
keyv.on('error', handleConnectionError)
```

Any valid [`Redis`](https://github.com/luin/ioredis#connect-to-redis) options will be passed directly through.
const keyv = new Keyv({
store: new KeyvRedis('redis://user:pass@localhost:6379')
})

e.g:

```js
const keyv = new Keyv('redis://user:pass@localhost:6379', { disable_resubscribing: true })
keyv.on('error', handleConnectionError)
```

Or you can manually create a storage adapter instance and pass it to Keyv:
Any valid [`Redis`](https://github.com/luin/ioredis#connect-to-redis) options will be passed directly through:

```js
const KeyvRedis = require('@keyvhq/redis')
const Keyv = require('@keyvhq/core')

const keyvRedis = new KeyvRedis('redis://user:pass@localhost:6379')
const keyv = new Keyv({ store: keyvRedis })
const keyv = new Keyv({
store: new KeyvRedis('redis://user:pass@localhost:6379', {
disable_resubscribing: true
})
})
```

Or reuse a previous Redis instance:
Or you can reuse a previously declared Redis instance:

```js
const KeyvRedis = require('@keyvhq/redis')
const Keyv = require('@keyvhq/core')
const Redis = require('ioredis')

const redis = new Redis('redis://user:pass@localhost:6379')
const keyvRedis = new KeyvRedis(redis)
const keyv = new Keyv({ store: keyvRedis })
const keyv = new Keyv({ store: new KeyvRedis(redis) })
```

## License
Expand Down
23 changes: 14 additions & 9 deletions packages/sqlite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@ SQLite storage adapter for [Keyv](https://github.com/microlinkhq/keyv).
## Install

```shell
npm install --save keyv @keyvhq/sqlite
npm install --save @keyvhq/core @keyvhq/sqlite
```

## Usage

```js
const KeyvSqlite = require('@keyvhq/sqlite')
const Keyv = require('@keyvhq/core')

const keyv = new Keyv('sqlite://path/to/database.sqlite')
keyv.on('error', handleConnectionError)
const keyv = new Keyv({
store: new KeyvSqlite('sqlite://path/to/database.sqlite')
})
```

You can specify the `table` and [`busyTimeout`](https://sqlite.org/c3ref/busy_timeout.html) option.

e.g:
You can specify the `table` and [`busyTimeout`](https://sqlite.org/c3ref/busy_timeout.html) option:

```js
const keyv = new Keyv('sqlite://path/to/database.sqlite', {
table: 'cache',
busyTimeout: 10000
const KeyvSqlite = require('@keyvhq/sqlite')
const Keyv = require('@keyvhq/core')

const keyv = new Keyv({
store: new KeyvSqlite('sqlite://path/to/database.sqlite', {
table: 'cache',
busyTimeout: 10000
})
})
```

Expand Down

0 comments on commit e898032

Please sign in to comment.