Skip to content
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

Dump RedisResult response structures to console/log/JSON/etc. #292

Closed
derekm opened this issue Jul 2, 2023 · 4 comments · Fixed by #353
Closed

Dump RedisResult response structures to console/log/JSON/etc. #292

derekm opened this issue Jul 2, 2023 · 4 comments · Fixed by #353
Labels
help wanted Extra attention is needed

Comments

@derekm
Copy link

derekm commented Jul 2, 2023

RedisResult structures can be quite complex and counterintuitive to navigate initially (being nested lists of lists of different sizes).

To support rapid prototyping, there should be a convenient way to dump response structures to a human-readable format for inspection during early development and debugging phases.

@rueian rueian added the help wanted Extra attention is needed label Jul 2, 2023
@rueian
Copy link
Collaborator

rueian commented Jul 2, 2023

I agree. One solution would be Implementing fmt.Stringer() on the RedisResult structure. The implementation would be similar to this:

rueidis/message.go

Lines 1027 to 1063 in 47c3d7c

func (m *RedisMessage) ToAny() (any, error) {
if err := m.Error(); err != nil {
return nil, err
}
switch m.typ {
case typeFloat:
return util.ToFloat64(m.string)
case typeBlobString, typeSimpleString, typeVerbatimString, typeBigNumber:
return m.string, nil
case typeBool:
return m.integer == 1, nil
case typeInteger:
return m.integer, nil
case typeMap:
vs := make(map[string]any, len(m.values)/2)
for i := 0; i < len(m.values); i += 2 {
if v, err := m.values[i+1].ToAny(); err != nil && !IsRedisNil(err) {
vs[m.values[i].string] = err
} else {
vs[m.values[i].string] = v
}
}
return vs, nil
case typeSet, typeArray:
vs := make([]any, len(m.values))
for i := 0; i < len(m.values); i++ {
if v, err := m.values[i].ToAny(); err != nil && !IsRedisNil(err) {
vs[i] = err
} else {
vs[i] = v
}
}
return vs, nil
}
typ := m.typ
panic(fmt.Sprintf("redis message type %s is not a supported in ToAny", typeNames[typ]))
}

@derekm
Copy link
Author

derekm commented Jul 2, 2023

Thanks for the tip, @rueian! I'll see if I can work something up for my own needs. Hopefully I come back soon with a PR!

@rueian
Copy link
Collaborator

rueian commented Jul 2, 2023

Thanks @derekm! I am really looking forward to it.

@rueian
Copy link
Collaborator

rueian commented Jul 17, 2023

Hi @derekm, hope you are doing well. Would you be still interested in implementing this feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants