@@ -487,6 +487,15 @@ func (r RedisResult) AsClientInfo() (v *ClientInfo, err error) {
487
487
return
488
488
}
489
489
490
+ func (r RedisResult ) AsACLLogEntry () (v []* ACLLogEntry , err error ) {
491
+ if r .err != nil {
492
+ err = r .err
493
+ } else {
494
+ v , err = r .val .AsACLLogEntry ()
495
+ }
496
+ return
497
+ }
498
+
490
499
// IsCacheHit delegates to RedisMessage.IsCacheHit
491
500
func (r RedisResult ) IsCacheHit () bool {
492
501
return r .val .IsCacheHit ()
@@ -1557,6 +1566,73 @@ func (m *RedisMessage) AsClientInfo() (*ClientInfo, error) {
1557
1566
return info , nil
1558
1567
}
1559
1568
1569
+ type ACLLogEntry struct {
1570
+ Count int64
1571
+ Reason string
1572
+ Context string
1573
+ Object string
1574
+ Username string
1575
+ AgeSeconds float64
1576
+ ClientInfo * ClientInfo
1577
+ EntryID int64
1578
+ TimestampCreated int64
1579
+ TimestampLastUpdated int64
1580
+ }
1581
+
1582
+ func (m * RedisMessage ) AsACLLogEntry () ([]* ACLLogEntry , error ) {
1583
+ arr , err := m .ToArray ()
1584
+ if err != nil {
1585
+ return nil , err
1586
+
1587
+ }
1588
+ logEntries := make ([]* ACLLogEntry , 0 , len (arr ))
1589
+
1590
+ for _ , msg := range arr {
1591
+ log , err := msg .AsMap ()
1592
+ if err != nil {
1593
+ return nil , err
1594
+ }
1595
+ entry := ACLLogEntry {}
1596
+
1597
+ if attr , ok := log ["count" ]; ok {
1598
+ entry .Count , err = attr .AsInt64 ()
1599
+ }
1600
+ if attr , ok := log ["reason" ]; ok {
1601
+ entry .Reason , err = attr .ToString ()
1602
+ }
1603
+ if attr , ok := log ["context" ]; ok {
1604
+ entry .Context , err = attr .ToString ()
1605
+ }
1606
+ if attr , ok := log ["object" ]; ok {
1607
+ entry .Object , err = attr .ToString ()
1608
+ }
1609
+ if attr , ok := log ["username" ]; ok {
1610
+ entry .Username , err = attr .ToString ()
1611
+ }
1612
+ if attr , ok := log ["age-seconds" ]; ok {
1613
+ entry .AgeSeconds , err = attr .AsFloat64 ()
1614
+ }
1615
+ if attr , ok := log ["client-info" ]; ok {
1616
+ entry .ClientInfo , err = attr .AsClientInfo ()
1617
+ }
1618
+ if attr , ok := log ["entry-id" ]; ok {
1619
+ entry .EntryID , err = attr .AsInt64 ()
1620
+ }
1621
+ if attr , ok := log ["timestamp-created" ]; ok {
1622
+ entry .TimestampCreated , err = attr .AsInt64 ()
1623
+ }
1624
+ if attr , ok := log ["timestamp-last-updated" ]; ok {
1625
+ entry .TimestampLastUpdated , err = attr .AsInt64 ()
1626
+ }
1627
+
1628
+ if err != nil {
1629
+ return nil , err
1630
+ }
1631
+ logEntries = append (logEntries , & entry )
1632
+ }
1633
+ return logEntries , nil
1634
+ }
1635
+
1560
1636
// ToMap check if message is a redis RESP3 map response, and return it
1561
1637
func (m * RedisMessage ) ToMap () (map [string ]RedisMessage , error ) {
1562
1638
if m .IsMap () {
0 commit comments