mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-10 21:02:21 +00:00
Fix the interface conversion errors in Redis (#334)
This commit is contained in:
parent
61f24320b8
commit
70982c2844
@ -296,12 +296,28 @@ func (p *RedisProtocol) Read() (packet *RedisPacket, err error) {
|
|||||||
switch x.(type) {
|
switch x.(type) {
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
array := x.([]interface{})
|
array := x.([]interface{})
|
||||||
packet.Command = RedisCommand(strings.ToUpper(string(array[0].([]uint8))))
|
switch array[0].(type) {
|
||||||
if len(array) > 1 {
|
case []uint8:
|
||||||
packet.Key = string(array[1].([]uint8))
|
packet.Command = RedisCommand(strings.ToUpper(string(array[0].([]uint8))))
|
||||||
}
|
if len(array) > 1 {
|
||||||
if len(array) > 2 {
|
packet.Key = string(array[1].([]uint8))
|
||||||
packet.Value = string(array[2].([]uint8))
|
}
|
||||||
|
if len(array) > 2 {
|
||||||
|
packet.Value = string(array[2].([]uint8))
|
||||||
|
}
|
||||||
|
if len(array) > 3 {
|
||||||
|
packet.Value = fmt.Sprintf("[%s", packet.Value)
|
||||||
|
for _, item := range array[3:] {
|
||||||
|
packet.Value = fmt.Sprintf("%s, %s", packet.Value, item.([]uint8))
|
||||||
|
}
|
||||||
|
packet.Value = strings.TrimSuffix(packet.Value, ", ")
|
||||||
|
packet.Value = fmt.Sprintf("%s]", packet.Value)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
msg := fmt.Sprintf("Unrecognized element in Redis array: %v\n", reflect.TypeOf(array[0]))
|
||||||
|
log.Printf(msg)
|
||||||
|
err = errors.New(msg)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
case []uint8:
|
case []uint8:
|
||||||
val := string(x.([]uint8))
|
val := string(x.([]uint8))
|
||||||
@ -316,6 +332,8 @@ func (p *RedisProtocol) Read() (packet *RedisPacket, err error) {
|
|||||||
}
|
}
|
||||||
case string:
|
case string:
|
||||||
packet.Value = x.(string)
|
packet.Value = x.(string)
|
||||||
|
case int64:
|
||||||
|
packet.Value = fmt.Sprintf("%d", x.(int64))
|
||||||
default:
|
default:
|
||||||
msg := fmt.Sprintf("Unrecognized Redis data type: %v\n", reflect.TypeOf(x))
|
msg := fmt.Sprintf("Unrecognized Redis data type: %v\n", reflect.TypeOf(x))
|
||||||
log.Printf(msg)
|
log.Printf(msg)
|
||||||
|
Loading…
Reference in New Issue
Block a user