-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
115 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export function replicaof(host, port) { | ||
if (!host || !port) { | ||
throw new Error("ERR wrong number of arguments for 'replicaof' command") | ||
} | ||
|
||
if (host.toUpperCase() === 'NO' && port.toUpperCase() === 'ONE') { | ||
return 'OK' | ||
} | ||
|
||
throw new Error('ERR Unsupported operation, PRs welcome ;-)') | ||
} | ||
|
||
export function replicaofBuffer(...args) { | ||
const val = replicaof.apply(this, args) | ||
return val ? Buffer.from(val) : val | ||
} | ||
|
||
// As of Redis version 5 the Redis project doesn't use the word slave, but it's included for backwards compatibility | ||
export const slaveof = replicaof | ||
export const slaveofBuffer = replicaofBuffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Redis from 'ioredis' | ||
|
||
// eslint-disable-next-line import/no-relative-parent-imports | ||
import { runTwinSuite } from '../../../test-utils' | ||
|
||
const suite = (command, equals) => { | ||
const redis = new Redis() | ||
|
||
afterAll(() => { | ||
redis.disconnect() | ||
}) | ||
|
||
it('should throw if incorrect number of arguments', async () => { | ||
expect.assertions(2) | ||
try { | ||
await redis[command]() | ||
} catch (err) { | ||
expect(err.message).toMatch('ERR wrong number of arguments') | ||
} | ||
|
||
try { | ||
await redis[command]('NO') | ||
} catch (err) { | ||
expect(err.message).toMatch('ERR wrong number of arguments') | ||
} | ||
}) | ||
|
||
it('should return "OK" when setting to NO ONE', async () => { | ||
expect(equals(await redis[command]('no', 'ONE'), 'OK')).toBe(true) | ||
expect(equals(await redis[command]('NO', 'one'), 'OK')).toBe(true) | ||
}) | ||
;(process.env.IS_E2E ? it.skip : it)( | ||
'should throw an error about unsupported functionality', | ||
async () => { | ||
expect.hasAssertions() | ||
try { | ||
await redis[command]('127.0.0.1', 6799) | ||
} catch (err) { | ||
expect(err.message).toMatch('ERR Unsupported operation') | ||
} | ||
} | ||
) | ||
} | ||
|
||
runTwinSuite('replicaof', (command, equals) => { | ||
describe(command, () => { | ||
suite(command, equals) | ||
}) | ||
}) | ||
runTwinSuite('slaveof', (command, equals) => { | ||
describe(command, () => { | ||
suite(command, equals) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.