-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support CLUSTER commands #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Support CLUSTER commands #2015
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6c2f69f
Support CLUSTER commands
7403892
add some client tests
df76319
remove only
b0f47d4
delete cluster slaves
e88cfda
delete reset clietn test
8600d97
SET SLOT
3e5212a
test with client
de14ee2
fix fail
a0c5f63
Update CLUSTER_COUNTKEYSINSLOT.spec.ts
Avital-Fine 818609e
move commands to client/commands.ts
1e2efb9
clusterNode
990afef
remove CLUSTER-SET-CONFIG-EPOCH test with client
e57785d
Merge branch 'master' of github.com:redis/node-redis into CLUSTER-Com…
leibale 4350c57
clean code
leibale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,19 @@ | ||
import { strict as assert } from 'assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import { transformArguments } from './CLUSTER_BUMPEPOCH'; | ||
|
||
describe('CLUSTER BUMPEPOCH', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments(), | ||
['CLUSTER', 'BUMPEPOCH'] | ||
); | ||
}); | ||
|
||
testUtils.testWithCluster('cluster.clusterBumpEpoch', async cluster => { | ||
assert.equal( | ||
typeof await cluster.getSlotMaster(0).client.clusterBumpEpoch(), | ||
'string' | ||
); | ||
}, GLOBAL.SERVERS.OPEN); | ||
}); |
This file contains hidden or 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,5 @@ | ||
export function transformArguments(): Array<string> { | ||
return ['CLUSTER', 'BUMPEPOCH']; | ||
} | ||
|
||
export declare function transformReply(): string; |
20 changes: 20 additions & 0 deletions
20
packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.spec.ts
This file contains hidden or 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 @@ | ||
import { strict as assert } from 'assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import { transformArguments } from './CLUSTER_COUNT-FAILURE-REPORTS'; | ||
|
||
describe('CLUSTER COUNT-FAILURE-REPORTS', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments('1'), | ||
['CLUSTER', 'COUNT-FAILURE-REPORTS', '1'] | ||
); | ||
}); | ||
|
||
testUtils.testWithCluster('cluster.clusterCountFailureReports', async cluster => { | ||
const id: string = await cluster.getSlotMaster(0).client.clusterMyId(); | ||
assert.equal( | ||
await cluster.getSlotMaster(0).client.clusterCountFailureReports(id), | ||
0 | ||
); | ||
}, GLOBAL.CLUSTERS.OPEN); | ||
}); |
5 changes: 5 additions & 0 deletions
5
packages/client/lib/commands/CLUSTER_COUNT-FAILURE-REPORTS.ts
This file contains hidden or 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,5 @@ | ||
export function transformArguments(nodeId: string): Array<string> { | ||
return ['CLUSTER', 'COUNT-FAILURE-REPORTS', nodeId]; | ||
} | ||
|
||
export declare function transformReply(): number; |
19 changes: 19 additions & 0 deletions
19
packages/client/lib/commands/CLUSTER_COUNTKEYSINSLOT.spec.ts
This file contains hidden or 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,19 @@ | ||
import { strict as assert } from 'assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import { transformArguments } from './CLUSTER_COUNTKEYSINSLOT'; | ||
|
||
describe('CLUSTER COUNTKEYSINSLOT', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments(1), | ||
['CLUSTER', 'COUNTKEYSINSLOT', '1'] | ||
); | ||
}); | ||
|
||
testUtils.testWithCluster('cluster.clusterInfo', async cluster => { | ||
assert.equal( | ||
typeof await cluster.getSlotMaster(0).client.clusterCountKeysInSlot(1), | ||
'number' | ||
); | ||
}, GLOBAL.CLUSTERS.OPEN); | ||
}); |
This file contains hidden or 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,5 @@ | ||
export function transformArguments(slot: number): Array<string> { | ||
return ['CLUSTER', 'COUNTKEYSINSLOT', slot.toString()]; | ||
} | ||
|
||
export declare function transformReply(): number; |
This file contains hidden or 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,11 @@ | ||
import { strict as assert } from 'assert'; | ||
import { transformArguments } from './CLUSTER_DELSLOTS'; | ||
|
||
describe('CLUSTER DELSLOTS', () => { | ||
it('simple', () => { | ||
assert.deepEqual( | ||
transformArguments('1'), | ||
['CLUSTER', 'DELSLOTS', '1'] | ||
); | ||
}); | ||
}); |
This file contains hidden or 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,7 @@ | ||
export function transformArguments(...slots: string[]): Array<string> { | ||
const args = ['CLUSTER', 'DELSLOTS']; | ||
args.push(...slots); | ||
return args; | ||
} | ||
|
||
export declare function transformReply(): string; |
This file contains hidden or 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,19 @@ | ||
import { strict as assert } from 'assert'; | ||
import { FailoverModes, transformArguments } from './CLUSTER_FAILOVER'; | ||
|
||
describe('CLUSTER FAILOVER', () => { | ||
describe('transformArguments', () => { | ||
it('simple', () => { | ||
assert.deepEqual( | ||
transformArguments(), | ||
['CLUSTER', 'FAILOVER'] | ||
); | ||
}); | ||
it('with mode', () => { | ||
assert.deepEqual( | ||
transformArguments(FailoverModes.FORCE), | ||
['CLUSTER', 'FAILOVER', 'FORCE'] | ||
); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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,16 @@ | ||
export enum FailoverModes { | ||
FORCE = 'FORCE', | ||
TAKEOVER = 'TAKEOVER' | ||
} | ||
|
||
export function transformArguments(mode?: FailoverModes): Array<string> { | ||
const args = ['CLUSTER', 'FAILOVER']; | ||
|
||
if (mode) { | ||
args.push(mode); | ||
} | ||
|
||
return args; | ||
} | ||
|
||
export declare function transformReply(): string; |
This file contains hidden or 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,11 @@ | ||
import { strict as assert } from 'assert'; | ||
import { transformArguments } from './CLUSTER_FORGET'; | ||
|
||
describe('CLUSTER FORGET', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments('0'), | ||
['CLUSTER', 'FORGET', '0'] | ||
); | ||
}); | ||
}); |
This file contains hidden or 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,5 @@ | ||
export function transformArguments(nodeId: string): Array<string> { | ||
return ['CLUSTER', 'FORGET', nodeId]; | ||
} | ||
|
||
export declare function transformReply(): string; |
This file contains hidden or 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 hidden or 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,11 @@ | ||
import { strict as assert } from 'assert'; | ||
import { transformArguments } from './CLUSTER_KEYSLOT'; | ||
|
||
describe('CLUSTER KEYSLOT', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments('key'), | ||
['CLUSTER', 'KEYSLOT', 'key'] | ||
); | ||
}); | ||
}); |
This file contains hidden or 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,5 @@ | ||
export function transformArguments(key: string): Array<string> { | ||
return ['CLUSTER', 'KEYSLOT', key]; | ||
} | ||
|
||
export declare function transformReply(): number; |
This file contains hidden or 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,19 @@ | ||
import { strict as assert } from 'assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import { transformArguments } from './CLUSTER_MYID'; | ||
|
||
describe('CLUSTER MYID', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments(), | ||
['CLUSTER', 'MYID'] | ||
); | ||
}); | ||
|
||
testUtils.testWithCluster('cluster.clusterMyId', async cluster => { | ||
assert.notEqual( | ||
await cluster.getSlotMaster(0).client.clusterMyId(), | ||
null | ||
); | ||
}, GLOBAL.CLUSTERS.OPEN); | ||
}); |
This file contains hidden or 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,5 @@ | ||
export function transformArguments(): Array<string> { | ||
return ['CLUSTER', 'MYID']; | ||
} | ||
|
||
export declare function transformReply(): string; |
This file contains hidden or 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,11 @@ | ||
import { strict as assert } from 'assert'; | ||
import { transformArguments } from './CLUSTER_REPLICAS'; | ||
|
||
describe('CLUSTER REPLICAS', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments('0'), | ||
['CLUSTER', 'REPLICAS', '0'] | ||
); | ||
}); | ||
}); |
This file contains hidden or 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,5 @@ | ||
export function transformArguments(nodeId: string): Array<string> { | ||
return ['CLUSTER', 'REPLICAS', nodeId]; | ||
} | ||
|
||
export { transformReply } from './CLUSTER_NODES' |
This file contains hidden or 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,11 @@ | ||
import { strict as assert } from 'assert'; | ||
import { transformArguments } from './CLUSTER_REPLICATE'; | ||
|
||
describe('CLUSTER REPLICATE', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments('0'), | ||
['CLUSTER', 'REPLICATE', '0'] | ||
); | ||
}); | ||
}); |
This file contains hidden or 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,5 @@ | ||
export function transformArguments(nodeId: string): Array<string> { | ||
return ['CLUSTER', 'REPLICATE', nodeId]; | ||
} | ||
|
||
export declare function transformReply(): string; |
This file contains hidden or 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,19 @@ | ||
import { strict as assert } from 'assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import { transformArguments } from './CLUSTER_SAVECONFIG'; | ||
|
||
describe('CLUSTER SAVECONFIG', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments(), | ||
['CLUSTER', 'SAVECONFIG'] | ||
); | ||
}); | ||
|
||
testUtils.testWithCluster('cluster.clusterSaveConfig', async cluster => { | ||
assert.equal( | ||
await cluster.getSlotMaster(0).client.clusterSaveConfig(), | ||
'OK' | ||
); | ||
}, GLOBAL.CLUSTERS.OPEN); | ||
}); |
This file contains hidden or 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,5 @@ | ||
export function transformArguments(): Array<string> { | ||
return ['CLUSTER', 'SAVECONFIG']; | ||
} | ||
|
||
export declare function transformReply(): string; |
23 changes: 23 additions & 0 deletions
23
packages/client/lib/commands/CLUSTER_SET-CONFIG-EPOCH.spec.ts
This file contains hidden or 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,23 @@ | ||
import { strict as assert } from 'assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import { transformArguments } from './CLUSTER_SET-CONFIG-EPOCH'; | ||
|
||
describe('CLUSTER SET-CONFIG-EPOCH', () => { | ||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments(0), | ||
['CLUSTER', 'SET-CONFIG-EPOCH', '0'] | ||
); | ||
}); | ||
|
||
testUtils.testWithCluster('cluster.clusterSetConfigEpoch', async cluster => { | ||
try { | ||
assert.equal( | ||
await cluster.getSlotMaster(0).client.clusterSetConfigEpoch(1), | ||
'OK' | ||
); | ||
} catch (ReplyError) { | ||
Avital-Fine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//? | ||
} | ||
}, GLOBAL.CLUSTERS.OPEN); | ||
}); |
This file contains hidden or 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,5 @@ | ||
export function transformArguments(configEpoch: number): Array<string> { | ||
return ['CLUSTER', 'SET-CONFIG-EPOCH', configEpoch.toString()]; | ||
} | ||
|
||
export declare function transformReply(): string; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.