Skip to content

Commit

Permalink
Merge pull request #38 from yannh/dump-all-dbs
Browse files Browse the repository at this point in the history
Add missing SELECT statement when dumping all dbs
  • Loading branch information
yannh authored Apr 23, 2022
2 parents 0c04870 + 65f0d87 commit 63080e1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion acceptance-tests/acceptance.bats
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
[ "$status" -eq 0 ]
}

@test "Dumping / restoring all databases" {
run tests/multiple-dbs.sh
[ "$status" -eq 0 ]
}

# https://github.com/yannh/redis-dump-go/issues/11
# https://github.com/yannh/redis-dump-go/issues/18
@test "Pass when importing a ZSET with 1M entries" {
Expand All @@ -31,4 +36,4 @@
@test "Pass when importing 1M key/values" {
run tests/1mkeys.sh
[ "$status" -eq 0 ]
}
}
27 changes: 27 additions & 0 deletions acceptance-tests/tests/multiple-dbs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh -e

NDBS=3

echo "-> Filling Redis with Mock Data..."
redis-cli -h redis FLUSHALL
for DB in `seq 1 $NDBS`; do
redis-cli -h redis -n $DB SET thisdb $DB
done

echo "-> Dumping DB..."
time /redis-dump-go -host redis -n 250 -output commands >backup

echo "-> Flushing DB and restoring dump..."
redis-cli -h redis FLUSHALL
redis-cli -h redis -n $DB --pipe <backup

NEWNDBS=`redis-cli -h redis info keyspace | grep keys | wc -l`

echo "-> Expecting right amount of DBS..."
if [ $NDBS -ne $NEWNDBS ]; then
echo "ERROR - only $NEWNDBS found, expected $NDBS"
exit 1
else
echo "OK - $NEWNDBS dbs"
exit 0
fi
2 changes: 2 additions & 0 deletions pkg/redisdump/redisdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ func dumpDB(client radix.Client, db *uint8, filter string, nWorkers int, withTTL
keyGenerator = scanKeysLegacy
}

logger.Print(serializer([]string{"SELECT", fmt.Sprint(*db)}))

errors := make(chan error)
nErrors := 0
go func() {
Expand Down

0 comments on commit 63080e1

Please sign in to comment.