Skip to content

Commit 7f0c3bc

Browse files
authored
Merge pull request #580 from go-redis/fix/flush-db-async
Add FlushDBAsync and FlushAllAsync
2 parents a2290b2 + 730d803 commit 7f0c3bc

16 files changed

+47
-23
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Redis client for Golang [![Build Status](https://travis-ci.org/go-redis/redis.png?branch=master)](https://travis-ci.org/go-redis/redis)
1+
# Redis client for Golang
2+
3+
[![Build Status](https://travis-ci.org/go-redis/redis.png?branch=master)](https://travis-ci.org/go-redis/redis)
4+
[![GoDoc](https://godoc.org/github.com/go-redis/redis?status.svg)](https://godoc.org/github.com/go-redis/redis)
25

36
Supports:
47

bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func benchmarkRedisClient(poolSize int) *redis.Client {
1616
WriteTimeout: time.Second,
1717
PoolSize: poolSize,
1818
})
19-
if err := client.FlushDb().Err(); err != nil {
19+
if err := client.FlushDB().Err(); err != nil {
2020
panic(err)
2121
}
2222
return client

cluster_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ var _ = Describe("ClusterClient", func() {
478478
}
479479

480480
err := client.ForEachMaster(func(master *redis.Client) error {
481-
return master.FlushDb().Err()
481+
return master.FlushDB().Err()
482482
})
483483
Expect(err).NotTo(HaveOccurred())
484484

@@ -496,7 +496,7 @@ var _ = Describe("ClusterClient", func() {
496496
client = cluster.clusterClient(opt)
497497

498498
_ = client.ForEachMaster(func(master *redis.Client) error {
499-
return master.FlushDb().Err()
499+
return master.FlushDB().Err()
500500
})
501501
})
502502

@@ -514,12 +514,12 @@ var _ = Describe("ClusterClient", func() {
514514
client = cluster.clusterClient(opt)
515515

516516
_ = client.ForEachMaster(func(master *redis.Client) error {
517-
return master.FlushDb().Err()
517+
return master.FlushDB().Err()
518518
})
519519
})
520520

521521
AfterEach(func() {
522-
client.FlushDb()
522+
client.FlushDB()
523523
Expect(client.Close()).NotTo(HaveOccurred())
524524
})
525525

command_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var _ = Describe("Cmd", func() {
1212

1313
BeforeEach(func() {
1414
client = redis.NewClient(redisOptions())
15-
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
15+
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
1616
})
1717

1818
AfterEach(func() {

commands.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ type Cmdable interface {
192192
ConfigSet(parameter, value string) *StatusCmd
193193
DbSize() *IntCmd
194194
FlushAll() *StatusCmd
195-
FlushDb() *StatusCmd
195+
FlushAllAsync() *StatusCmd
196+
FlushDB() *StatusCmd
197+
FlushDBAsync() *StatusCmd
196198
Info(section ...string) *StringCmd
197199
LastSave() *IntCmd
198200
Save() *StatusCmd
@@ -1685,12 +1687,31 @@ func (c *cmdable) FlushAll() *StatusCmd {
16851687
return cmd
16861688
}
16871689

1690+
func (c *cmdable) FlushAllAsync() *StatusCmd {
1691+
cmd := NewStatusCmd("flushall", "async")
1692+
c.process(cmd)
1693+
return cmd
1694+
}
1695+
1696+
// Deprecated. Use FlushDB instead.
16881697
func (c *cmdable) FlushDb() *StatusCmd {
16891698
cmd := NewStatusCmd("flushdb")
16901699
c.process(cmd)
16911700
return cmd
16921701
}
16931702

1703+
func (c *cmdable) FlushDB() *StatusCmd {
1704+
cmd := NewStatusCmd("flushdb")
1705+
c.process(cmd)
1706+
return cmd
1707+
}
1708+
1709+
func (c *cmdable) FlushDBAsync() *StatusCmd {
1710+
cmd := NewStatusCmd("flushdb", "async")
1711+
c.process(cmd)
1712+
return cmd
1713+
}
1714+
16941715
func (c *cmdable) Info(section ...string) *StringCmd {
16951716
args := []interface{}{"info"}
16961717
if len(section) > 0 {

commands_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var _ = Describe("Commands", func() {
1717

1818
BeforeEach(func() {
1919
client = redis.NewClient(redisOptions())
20-
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
20+
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
2121
})
2222

2323
AfterEach(func() {
@@ -352,7 +352,7 @@ var _ = Describe("Commands", func() {
352352
pipe := client.Pipeline()
353353
pipe.Select(2)
354354
get = pipe.Get("key")
355-
pipe.FlushDb()
355+
pipe.FlushDB()
356356

357357
_, err := pipe.Exec()
358358
Expect(err).NotTo(HaveOccurred())

example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func init() {
2020
PoolSize: 10,
2121
PoolTimeout: 30 * time.Second,
2222
})
23-
client.FlushDb()
23+
client.FlushDB()
2424
}
2525

2626
func ExampleNewClient() {
@@ -147,7 +147,7 @@ func ExampleClient_BLPop() {
147147
}
148148

149149
func ExampleClient_Scan() {
150-
client.FlushDb()
150+
client.FlushDB()
151151
for i := 0; i < 33; i++ {
152152
err := client.Set(fmt.Sprintf("key%d", i), "value", 0).Err()
153153
if err != nil {

iterator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var _ = Describe("ScanIterator", func() {
4545

4646
BeforeEach(func() {
4747
client = redis.NewClient(redisOptions())
48-
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
48+
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
4949
})
5050

5151
AfterEach(func() {

pipeline_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var _ = Describe("pipelining", func() {
1313

1414
BeforeEach(func() {
1515
client = redis.NewClient(redisOptions())
16-
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
16+
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
1717
})
1818

1919
AfterEach(func() {

pool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var _ = Describe("pool", func() {
1414

1515
BeforeEach(func() {
1616
client = redis.NewClient(redisOptions())
17-
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
17+
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
1818
})
1919

2020
AfterEach(func() {

0 commit comments

Comments
 (0)