Skip to content

Commit

Permalink
docs: 📚️ document constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
vpriem committed Aug 16, 2023
1 parent 9206368 commit 9896edd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 8 additions & 9 deletions README.md
Expand Up @@ -76,7 +76,8 @@ yarn add @tiermobility/tile38-ts

```typescript
import { Tile38 } from '@tiermobility/tile38-ts';
const tile38 = new Tile38({ url: 'leader:9851' });

const tile38 = new Tile38('leader:9851');
```

### Leader / Follower
Expand All @@ -88,8 +89,7 @@ This client is not meant to setup a replication, because this should happen in y
For now we allow for one follower `URI` to bet set alongside the leader `URI`.

```typescript
import { Tile38 } from '@tiermobility/tile38-ts';
const tile38 = new Tile38({ url: 'leader:9851', followerUrl: 'follower:9851' });
const tile38 = new Tile38('leader:9851', 'follower:9851');
```

Once the client is instantiated with a follower, commands can be explicitly send
Expand All @@ -104,17 +104,16 @@ await tile38.follower().get('fleet', 'truck1').asObjects();
We expose `ioredis` [RedisOptions](https://redis.github.io/ioredis/index.html#RedisOptions).

```typescript
import { Tile38 } from '@tiermobility/tile38-ts';
const tile38 = new Tile38({
url: 'leader:9851',
followerUrl: 'follower:9851',
new Tile38(
'leader:9851',
'follower:9851',
// e.g. to set a retry strategy
redisOptions: {
{
retryStrategy: (times) => {
return Math.min(times * 50, 2000);
},
},
});
);
```

### Pagination
Expand Down
17 changes: 16 additions & 1 deletion src/tests/leader.test.ts
Expand Up @@ -23,13 +23,28 @@ describe('leader', () => {
await expect(tile38.ping()).resolves.toMatchObject({ ping: 'pong' });
});

it('should create with port and options', async () => {
tile38 = new Tile38(9851, { port: 9876 });
expect(() => tile38.follower()).toThrow('No Follower');
await expect(tile38.ping()).resolves.toMatchObject({ ping: 'pong' });
});

it('should create with port and host', async () => {
tile38 = new Tile38(9851, '127.0.0.1');
expect(() => tile38.follower()).toThrow('No Follower');
await expect(tile38.ping()).resolves.toMatchObject({ ping: 'pong' });
});

it('should create with object', async () => {
it('should create with port, host and options', async () => {
tile38 = new Tile38(9851, '127.0.0.1', {
port: 9876,
host: '192.168.19.98',
});
expect(() => tile38.follower()).toThrow('No Follower');
await expect(tile38.ping()).resolves.toMatchObject({ ping: 'pong' });
});

it('should create with options', async () => {
tile38 = new Tile38({ connectTimeout: 1000 });
expect(() => tile38.follower()).toThrow('No Follower');
await expect(tile38.ping()).resolves.toMatchObject({ ping: 'pong' });
Expand Down

0 comments on commit 9896edd

Please sign in to comment.