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

[miniredis] Add maxCullLen to minirdis.Dump() #268

Merged
merged 1 commit into from May 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion miniredis.go
Expand Up @@ -29,6 +29,8 @@ import (
"github.com/alicebob/miniredis/v2/server"
)

var DumpMaxLineLen = 60

type hashKey map[string]string
type listKey []string
type setKey map[string]struct{}
Expand Down Expand Up @@ -341,12 +343,19 @@ func (m *Miniredis) Server() *server.Server {
}

// Dump returns a text version of the selected DB, usable for debugging.
//
// Dump limits the maximum length of each key:value to "DumpMaxLineLen" characters.
// To increase that, call something like:
//
// miniredis.DumpMaxLineLen = 1024
// mr, _ = miniredis.Run()
// mr.Dump()
func (m *Miniredis) Dump() string {
m.Lock()
defer m.Unlock()

var (
maxLen = 60
maxLen = DumpMaxLineLen
indent = " "
db = m.db(m.selectedDB)
r = ""
Expand All @@ -359,6 +368,7 @@ func (m *Miniredis) Dump() string {
return fmt.Sprintf("%q%s", s, suffix)
}
)

for _, k := range db.allKeys() {
r += fmt.Sprintf("- %s\n", k)
t := db.t(k)
Expand Down