Skip to content

Commit 43b4efe

Browse files
borsucokBridgeAR
authored andcommitted
fix: xreadgroup command keys parsing (#31)
* fix: xread and xreadgroup command keys parsing * commands.json update
1 parent 7dda215 commit 43b4efe

File tree

3 files changed

+87
-16
lines changed

3 files changed

+87
-16
lines changed

commands.json

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"bgrewriteaof": {
3434
"arity": 1,
3535
"flags": [
36-
"admin"
36+
"admin",
37+
"noscript"
3738
],
3839
"keyStart": 0,
3940
"keyStop": 0,
@@ -42,7 +43,8 @@
4243
"bgsave": {
4344
"arity": -1,
4445
"flags": [
45-
"admin"
46+
"admin",
47+
"noscript"
4648
],
4749
"keyStart": 0,
4850
"keyStop": 0,
@@ -161,6 +163,7 @@
161163
"command": {
162164
"arity": 1,
163165
"flags": [
166+
"random",
164167
"loading",
165168
"stale"
166169
],
@@ -172,6 +175,7 @@
172175
"arity": -2,
173176
"flags": [
174177
"admin",
178+
"noscript",
175179
"loading",
176180
"stale"
177181
],
@@ -243,7 +247,8 @@
243247
"dump": {
244248
"arity": 2,
245249
"flags": [
246-
"readonly"
250+
"readonly",
251+
"random"
247252
],
248253
"keyStart": 1,
249254
"keyStop": 1,
@@ -485,7 +490,8 @@
485490
"hgetall": {
486491
"arity": 2,
487492
"flags": [
488-
"readonly"
493+
"readonly",
494+
"random"
489495
],
490496
"keyStart": 1,
491497
"keyStop": 1,
@@ -652,6 +658,7 @@
652658
"info": {
653659
"arity": -1,
654660
"flags": [
661+
"random",
655662
"loading",
656663
"stale"
657664
],
@@ -720,6 +727,15 @@
720727
"keyStop": 1,
721728
"step": 1
722729
},
730+
"lolwut": {
731+
"arity": -1,
732+
"flags": [
733+
"readonly"
734+
],
735+
"keyStart": 0,
736+
"keyStop": 0,
737+
"step": 0
738+
},
723739
"lpop": {
724740
"arity": 2,
725741
"flags": [
@@ -792,7 +808,8 @@
792808
"memory": {
793809
"arity": -2,
794810
"flags": [
795-
"readonly"
811+
"readonly",
812+
"random"
796813
],
797814
"keyStart": 0,
798815
"keyStop": 0,
@@ -812,6 +829,7 @@
812829
"arity": -6,
813830
"flags": [
814831
"write",
832+
"random",
815833
"movablekeys"
816834
],
817835
"keyStart": 0,
@@ -881,7 +899,8 @@
881899
"object": {
882900
"arity": -2,
883901
"flags": [
884-
"readonly"
902+
"readonly",
903+
"random"
885904
],
886905
"keyStart": 2,
887906
"keyStop": 2,
@@ -1022,6 +1041,7 @@
10221041
"arity": 2,
10231042
"flags": [
10241043
"readonly",
1044+
"random",
10251045
"fast"
10261046
],
10271047
"keyStart": 1,
@@ -1134,6 +1154,17 @@
11341154
"keyStop": 0,
11351155
"step": 0
11361156
},
1157+
"replicaof": {
1158+
"arity": 3,
1159+
"flags": [
1160+
"admin",
1161+
"noscript",
1162+
"stale"
1163+
],
1164+
"keyStart": 0,
1165+
"keyStop": 0,
1166+
"step": 0
1167+
},
11371168
"restore": {
11381169
"arity": -4,
11391170
"flags": [
@@ -1343,6 +1374,7 @@
13431374
"arity": -1,
13441375
"flags": [
13451376
"admin",
1377+
"noscript",
13461378
"loading",
13471379
"stale"
13481380
],
@@ -1394,7 +1426,8 @@
13941426
"slowlog": {
13951427
"arity": -2,
13961428
"flags": [
1397-
"admin"
1429+
"admin",
1430+
"random"
13981431
],
13991432
"keyStart": 0,
14001433
"keyStop": 0,
@@ -1568,6 +1601,7 @@
15681601
"arity": 2,
15691602
"flags": [
15701603
"readonly",
1604+
"random",
15711605
"fast"
15721606
],
15731607
"keyStart": 1,
@@ -1636,7 +1670,7 @@
16361670
"step": 1
16371671
},
16381672
"xack": {
1639-
"arity": -3,
1673+
"arity": -4,
16401674
"flags": [
16411675
"write",
16421676
"fast"
@@ -1650,24 +1684,26 @@
16501684
"flags": [
16511685
"write",
16521686
"denyoom",
1687+
"random",
16531688
"fast"
16541689
],
16551690
"keyStart": 1,
16561691
"keyStop": 1,
16571692
"step": 1
16581693
},
16591694
"xclaim": {
1660-
"arity": -5,
1695+
"arity": -6,
16611696
"flags": [
16621697
"write",
1698+
"random",
16631699
"fast"
16641700
],
16651701
"keyStart": 1,
16661702
"keyStop": 1,
16671703
"step": 1
16681704
},
16691705
"xdel": {
1670-
"arity": -2,
1706+
"arity": -3,
16711707
"flags": [
16721708
"write",
16731709
"fast"
@@ -1689,7 +1725,8 @@
16891725
"xinfo": {
16901726
"arity": -2,
16911727
"flags": [
1692-
"readonly"
1728+
"readonly",
1729+
"random"
16931730
],
16941731
"keyStart": 2,
16951732
"keyStop": 2,
@@ -1708,7 +1745,8 @@
17081745
"xpending": {
17091746
"arity": -3,
17101747
"flags": [
1711-
"readonly"
1748+
"readonly",
1749+
"random"
17121750
],
17131751
"keyStart": 1,
17141752
"keyStop": 1,
@@ -1724,7 +1762,7 @@
17241762
"step": 1
17251763
},
17261764
"xread": {
1727-
"arity": -3,
1765+
"arity": -4,
17281766
"flags": [
17291767
"readonly",
17301768
"noscript",
@@ -1735,7 +1773,7 @@
17351773
"step": 1
17361774
},
17371775
"xreadgroup": {
1738-
"arity": -3,
1776+
"arity": -7,
17391777
"flags": [
17401778
"write",
17411779
"noscript",
@@ -1754,10 +1792,22 @@
17541792
"keyStop": 1,
17551793
"step": 1
17561794
},
1795+
"xsetid": {
1796+
"arity": 3,
1797+
"flags": [
1798+
"write",
1799+
"denyoom",
1800+
"fast"
1801+
],
1802+
"keyStart": 1,
1803+
"keyStop": 1,
1804+
"step": 1
1805+
},
17571806
"xtrim": {
17581807
"arity": -2,
17591808
"flags": [
17601809
"write",
1810+
"random",
17611811
"fast"
17621812
],
17631813
"keyStart": 1,
@@ -1834,7 +1884,7 @@
18341884
"fast"
18351885
],
18361886
"keyStart": 1,
1837-
"keyStop": -1,
1887+
"keyStop": 1,
18381888
"step": 1
18391889
},
18401890
"zpopmin": {
@@ -1844,7 +1894,7 @@
18441894
"fast"
18451895
],
18461896
"keyStart": 1,
1847-
"keyStop": -1,
1897+
"keyStop": 1,
18481898
"step": 1
18491899
},
18501900
"zrange": {

index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ exports.getKeyIndexes = function (commandName, args, options) {
131131
keys.push(2)
132132
}
133133
break
134+
case 'xreadgroup':
135+
case 'xread':
136+
// keys are 1st half of the args after STREAMS argument
137+
for (i = commandName === 'xread' ? 0 : 3; i < args.length - 1; i++) {
138+
if (String(args[i]).toUpperCase() === 'STREAMS') {
139+
140+
for (j = i + 1; j <= i + ((args.length - 1 - i) / 2); j++) {
141+
keys.push(j)
142+
}
143+
break
144+
}
145+
}
146+
break
134147
default:
135148
// step has to be at least one in this case, otherwise the command does not contain a key
136149
if (command.step > 0) {

test/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ describe('redis-commands', function () {
9292
expect(index('migrate', ['127.0.0.1', 6379, 'foo', 0, 0, 'COPY'])).to.eql([2])
9393
expect(index('migrate', ['127.0.0.1', 6379, '', 0, 0, 'REPLACE', 'KEYS', 'foo', 'bar'])).to.eql([7, 8])
9494
expect(index('migrate', ['127.0.0.1', 6379, '', 0, 0, 'KEYS', 'foo', 'bar'])).to.eql([6, 7])
95+
expect(index('xreadgroup', ['GROUP', 'group', 'consumer', 'COUNT', 10, 'BLOCK', 2000, 'NOACK', 'STREAMS', 'key1', 'key2', 'id1', 'id2'])).to.eql([9, 10])
96+
expect(index('xreadgroup', ['GROUP', 'group', 'consumer', 'STREAMS', 'key1', 'id1'])).to.eql([4])
97+
expect(index('xreadgroup', ['GROUP', 'group', 'consumer', 'STREAMS', 'key1', 'key2', 'id1', 'id2'])).to.eql([4, 5])
98+
expect(index('xreadgroup', ['GROUP', 'group', 'consumer', 'STREAMS', 'key1', 'key2', 'key3', 'id1', 'id2', 'id3'])).to.eql([4, 5, 6])
99+
expect(index('xread', ['COUNT', 10, 'BLOCK', 2000, 'STREAMS', 'key1', 'key2', 'id1', 'id2'])).to.eql([5, 6])
100+
expect(index('xread', ['STREAMS', 'key1', 'id1'])).to.eql([1])
101+
expect(index('xread', ['STREAMS', 'key1', 'key2', 'id1', 'id2'])).to.eql([1, 2])
102+
expect(index('xread', ['STREAMS', 'key1', 'key2', 'key3', 'id1', 'id2', 'id3'])).to.eql([1, 2, 3])
95103
})
96104

97105
it('should support numeric argument', function () {

0 commit comments

Comments
 (0)