Skip to content

Commit

Permalink
feat: constructor can accept both server as a string or servers as an…
Browse files Browse the repository at this point in the history
… array
  • Loading branch information
alexzel committed Feb 1, 2023
1 parent 9c95889 commit 6bdc83e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const iomem = new Mem(['127.0.0.1:11211'], { timeout: 500, retries: 2 })
...
```

The first argument also accepts a string when you have only one server.

See [Custom servers](#custom-servers) and [Options](#options) for more details.

### Basic usage
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Transform } from 'node:stream';

declare class Mem {
constructor(servers?: Mem.Addresses, options?: Mem.Options);
constructor(servers?: Mem.Addresses|Mem.Address, options?: Mem.Options);

static DEFAULT_EXPIRY: Mem.Expiry;
static setDefaultExpiry(expiry?: Mem.Expiry): void;
Expand Down
4 changes: 4 additions & 0 deletions src/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ class Net {
this._servers = new Map()
this._opaque = 0

if (!Array.isArray(servers)) {
servers = [servers]
}

servers.forEach(address => {
const server = new Server(address, this._options.maxConnections, this._options.connectionTimeout, this._options.keepAliveInitialDelay)
this._servers.set(server.hostname, server)
Expand Down
2 changes: 1 addition & 1 deletion test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('client', () => {
}

beforeAll(() => {
iomem = new Mem(['memcached:test@127.0.0.1'], {
iomem = new Mem('memcached:test@127.0.0.1', {
connectionTimeout: 500,
timeout: 1000
})
Expand Down

0 comments on commit 6bdc83e

Please sign in to comment.