@@ -1289,6 +1289,96 @@ func (cmd *XPendingExtCmd) readReply(rd *proto.Reader) error {
1289
1289
1290
1290
//------------------------------------------------------------------------------
1291
1291
1292
+ type XInfoGroupsCmd struct {
1293
+ baseCmd
1294
+ val []XGroup
1295
+ }
1296
+
1297
+ type XGroup struct {
1298
+ Name string
1299
+ Consumers int64
1300
+ Pending int64
1301
+ LastDeliveredID string
1302
+ }
1303
+
1304
+ var _ Cmder = (* XInfoGroupsCmd )(nil )
1305
+
1306
+ func NewXInfoGroupsCmd (stream string ) * XInfoGroupsCmd {
1307
+ return & XInfoGroupsCmd {
1308
+ baseCmd : baseCmd {args : []interface {}{"xinfo" , "groups" , stream }},
1309
+ }
1310
+ }
1311
+
1312
+ func (cmd * XInfoGroupsCmd ) Val () []XGroup {
1313
+ return cmd .val
1314
+ }
1315
+
1316
+ func (cmd * XInfoGroupsCmd ) Result () ([]XGroup , error ) {
1317
+ return cmd .val , cmd .err
1318
+ }
1319
+
1320
+ func (cmd * XInfoGroupsCmd ) String () string {
1321
+ return cmdString (cmd , cmd .val )
1322
+ }
1323
+
1324
+ func (cmd * XInfoGroupsCmd ) readReply (rd * proto.Reader ) error {
1325
+ _ , cmd .err = rd .ReadArrayReply (
1326
+ func (rd * proto.Reader , n int64 ) (interface {}, error ) {
1327
+ for i := int64 (0 ); i < n ; i ++ {
1328
+ v , err := rd .ReadReply (xGroupInfoParser )
1329
+ if err != nil {
1330
+ return nil , err
1331
+ }
1332
+ cmd .val = append (cmd .val , v .(XGroup ))
1333
+ }
1334
+ return nil , nil
1335
+ })
1336
+ return nil
1337
+ }
1338
+
1339
+ func xGroupInfoParser (rd * proto.Reader , n int64 ) (interface {}, error ) {
1340
+ if n != 8 {
1341
+ return nil , fmt .Errorf ("redis: got %d elements in XINFO GROUPS reply," +
1342
+ "wanted 8" , n )
1343
+ }
1344
+ var (
1345
+ err error
1346
+ grp XGroup
1347
+ key string
1348
+ val string
1349
+ )
1350
+
1351
+ for i := 0 ; i < 4 ; i ++ {
1352
+ key , err = rd .ReadString ()
1353
+ if err != nil {
1354
+ return nil , err
1355
+ }
1356
+ val , err = rd .ReadString ()
1357
+ if err != nil {
1358
+ return nil , err
1359
+ }
1360
+ switch key {
1361
+ case "name" :
1362
+ grp .Name = val
1363
+ case "consumers" :
1364
+ grp .Consumers , err = strconv .ParseInt (val , 0 , 64 )
1365
+ case "pending" :
1366
+ grp .Pending , err = strconv .ParseInt (val , 0 , 64 )
1367
+ case "last-delivered-id" :
1368
+ grp .LastDeliveredID = val
1369
+ default :
1370
+ return nil , fmt .Errorf ("redis: unexpected content %s " +
1371
+ "in XINFO GROUPS reply" , key )
1372
+ }
1373
+ if err != nil {
1374
+ return nil , err
1375
+ }
1376
+ }
1377
+ return grp , err
1378
+ }
1379
+
1380
+ //------------------------------------------------------------------------------
1381
+
1292
1382
type ZSliceCmd struct {
1293
1383
baseCmd
1294
1384
0 commit comments