-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add support for PUBSUB SHARDNUMSUB
#2541
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { strict as assert } from 'assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import { transformArguments } from './PUBSUB_SHARDNUMSUB'; | ||
|
||
describe('PUBSUB SHARDNUMSUB', () => { | ||
describe('transformArguments', () => { | ||
it('simple', () => { | ||
assert.deepEqual( | ||
transformArguments(), | ||
['PUBSUB', 'SHARDNUMSUB'] | ||
); | ||
}); | ||
|
||
it('string', () => { | ||
assert.deepEqual( | ||
transformArguments('channel'), | ||
['PUBSUB', 'SHARDNUMSUB', 'channel'] | ||
); | ||
}); | ||
|
||
it('array', () => { | ||
assert.deepEqual( | ||
transformArguments(['1', '2']), | ||
['PUBSUB', 'SHARDNUMSUB', '1', '2'] | ||
); | ||
}); | ||
}); | ||
|
||
testUtils.testWithClient('client.pubSubShardNumSub', async client => { | ||
assert.deepEqual( | ||
await client.pubSubShardNumSub(), | ||
Object.create(null) | ||
); | ||
}, GLOBAL.SERVERS.OPEN); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { pushVerdictArguments } from './generic-transformers'; | ||
import { RedisCommandArgument, RedisCommandArguments } from '.'; | ||
|
||
export const IS_READ_ONLY = true; | ||
|
||
export function transformArguments( | ||
channels?: Array<RedisCommandArgument> | RedisCommandArgument | ||
): RedisCommandArguments { | ||
const args = ['PUBSUB', 'SHARDNUMSUB']; | ||
|
||
if (channels) return pushVerdictArguments(args, channels); | ||
|
||
return args; | ||
} | ||
|
||
export function transformReply(rawReply: Array<string | number>): Record<string, number> { | ||
const transformedReply = Object.create(null); | ||
|
||
for (let i = 0; i < rawReply.length; i +=2) { | ||
|
||
transformedReply[rawReply[i]] = rawReply[i + 1]; | ||
} | ||
|
||
return transformedReply; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please make the test "non empty" so it'll actually test
transforReply
as well?