Skip to content

Commit

Permalink
Merge pull request #268 from afjoseph/addMaxLen
Browse files Browse the repository at this point in the history
configurable DumpMaxLineLen in miniredis.Dump()
  • Loading branch information
alicebob committed May 21, 2022
2 parents db6f7f5 + 4847602 commit c6a13ad
Showing 1 changed file with 11 additions and 1 deletion.
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

0 comments on commit c6a13ad

Please sign in to comment.