mirror of https://github.com/go-redis/redis.git
Merge pull request #580 from go-redis/fix/flush-db-async
Add FlushDBAsync and FlushAllAsync
This commit is contained in:
commit
e14976b254
|
@ -1,4 +1,7 @@
|
|||
# Redis client for Golang [![Build Status](https://travis-ci.org/go-redis/redis.png?branch=master)](https://travis-ci.org/go-redis/redis)
|
||||
# Redis client for Golang
|
||||
|
||||
[![Build Status](https://travis-ci.org/go-redis/redis.png?branch=master)](https://travis-ci.org/go-redis/redis)
|
||||
[![GoDoc](https://godoc.org/github.com/go-redis/redis?status.svg)](https://godoc.org/github.com/go-redis/redis)
|
||||
|
||||
Supports:
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ func benchmarkRedisClient(poolSize int) *redis.Client {
|
|||
WriteTimeout: time.Second,
|
||||
PoolSize: poolSize,
|
||||
})
|
||||
if err := client.FlushDb().Err(); err != nil {
|
||||
if err := client.FlushDB().Err(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return client
|
||||
|
|
|
@ -478,7 +478,7 @@ var _ = Describe("ClusterClient", func() {
|
|||
}
|
||||
|
||||
err := client.ForEachMaster(func(master *redis.Client) error {
|
||||
return master.FlushDb().Err()
|
||||
return master.FlushDB().Err()
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
|
@ -496,7 +496,7 @@ var _ = Describe("ClusterClient", func() {
|
|||
client = cluster.clusterClient(opt)
|
||||
|
||||
_ = client.ForEachMaster(func(master *redis.Client) error {
|
||||
return master.FlushDb().Err()
|
||||
return master.FlushDB().Err()
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -514,12 +514,12 @@ var _ = Describe("ClusterClient", func() {
|
|||
client = cluster.clusterClient(opt)
|
||||
|
||||
_ = client.ForEachMaster(func(master *redis.Client) error {
|
||||
return master.FlushDb().Err()
|
||||
return master.FlushDB().Err()
|
||||
})
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
client.FlushDb()
|
||||
client.FlushDB()
|
||||
Expect(client.Close()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ var _ = Describe("Cmd", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
client = redis.NewClient(redisOptions())
|
||||
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
|
||||
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
|
23
commands.go
23
commands.go
|
@ -192,7 +192,9 @@ type Cmdable interface {
|
|||
ConfigSet(parameter, value string) *StatusCmd
|
||||
DbSize() *IntCmd
|
||||
FlushAll() *StatusCmd
|
||||
FlushDb() *StatusCmd
|
||||
FlushAllAsync() *StatusCmd
|
||||
FlushDB() *StatusCmd
|
||||
FlushDBAsync() *StatusCmd
|
||||
Info(section ...string) *StringCmd
|
||||
LastSave() *IntCmd
|
||||
Save() *StatusCmd
|
||||
|
@ -1685,12 +1687,31 @@ func (c *cmdable) FlushAll() *StatusCmd {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func (c *cmdable) FlushAllAsync() *StatusCmd {
|
||||
cmd := NewStatusCmd("flushall", "async")
|
||||
c.process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Deprecated. Use FlushDB instead.
|
||||
func (c *cmdable) FlushDb() *StatusCmd {
|
||||
cmd := NewStatusCmd("flushdb")
|
||||
c.process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *cmdable) FlushDB() *StatusCmd {
|
||||
cmd := NewStatusCmd("flushdb")
|
||||
c.process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *cmdable) FlushDBAsync() *StatusCmd {
|
||||
cmd := NewStatusCmd("flushdb", "async")
|
||||
c.process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *cmdable) Info(section ...string) *StringCmd {
|
||||
args := []interface{}{"info"}
|
||||
if len(section) > 0 {
|
||||
|
|
|
@ -17,7 +17,7 @@ var _ = Describe("Commands", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
client = redis.NewClient(redisOptions())
|
||||
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
|
||||
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
@ -352,7 +352,7 @@ var _ = Describe("Commands", func() {
|
|||
pipe := client.Pipeline()
|
||||
pipe.Select(2)
|
||||
get = pipe.Get("key")
|
||||
pipe.FlushDb()
|
||||
pipe.FlushDB()
|
||||
|
||||
_, err := pipe.Exec()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
|
|
@ -20,7 +20,7 @@ func init() {
|
|||
PoolSize: 10,
|
||||
PoolTimeout: 30 * time.Second,
|
||||
})
|
||||
client.FlushDb()
|
||||
client.FlushDB()
|
||||
}
|
||||
|
||||
func ExampleNewClient() {
|
||||
|
@ -147,7 +147,7 @@ func ExampleClient_BLPop() {
|
|||
}
|
||||
|
||||
func ExampleClient_Scan() {
|
||||
client.FlushDb()
|
||||
client.FlushDB()
|
||||
for i := 0; i < 33; i++ {
|
||||
err := client.Set(fmt.Sprintf("key%d", i), "value", 0).Err()
|
||||
if err != nil {
|
||||
|
|
|
@ -45,7 +45,7 @@ var _ = Describe("ScanIterator", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
client = redis.NewClient(redisOptions())
|
||||
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
|
||||
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
|
|
@ -13,7 +13,7 @@ var _ = Describe("pipelining", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
client = redis.NewClient(redisOptions())
|
||||
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
|
||||
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
|
|
@ -14,7 +14,7 @@ var _ = Describe("pool", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
client = redis.NewClient(redisOptions())
|
||||
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
|
||||
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
|
|
@ -17,7 +17,7 @@ var _ = Describe("PubSub", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
client = redis.NewClient(redisOptions())
|
||||
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
|
||||
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
|
|
@ -20,7 +20,7 @@ var _ = Describe("races", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
client = redis.NewClient(redisOptions())
|
||||
Expect(client.FlushDb().Err()).To(BeNil())
|
||||
Expect(client.FlushDB().Err()).To(BeNil())
|
||||
|
||||
C, N = 10, 1000
|
||||
if testing.Short() {
|
||||
|
|
|
@ -16,7 +16,7 @@ var _ = Describe("Client", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
client = redis.NewClient(redisOptions())
|
||||
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
|
||||
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
@ -111,7 +111,7 @@ var _ = Describe("Client", func() {
|
|||
Addr: redisAddr,
|
||||
DB: 2,
|
||||
})
|
||||
Expect(db2.FlushDb().Err()).NotTo(HaveOccurred())
|
||||
Expect(db2.FlushDB().Err()).NotTo(HaveOccurred())
|
||||
Expect(db2.Get("db").Err()).To(Equal(redis.Nil))
|
||||
Expect(db2.Set("db", 2, 0).Err()).NotTo(HaveOccurred())
|
||||
|
||||
|
@ -121,7 +121,7 @@ var _ = Describe("Client", func() {
|
|||
|
||||
Expect(client.Get("db").Err()).To(Equal(redis.Nil))
|
||||
|
||||
Expect(db2.FlushDb().Err()).NotTo(HaveOccurred())
|
||||
Expect(db2.FlushDB().Err()).NotTo(HaveOccurred())
|
||||
Expect(db2.Close()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ var _ = Describe("Redis Ring", func() {
|
|||
ring = redis.NewRing(opt)
|
||||
|
||||
err := ring.ForEachShard(func(cl *redis.Client) error {
|
||||
return cl.FlushDb().Err()
|
||||
return cl.FlushDB().Err()
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
|
|
@ -15,7 +15,7 @@ var _ = Describe("Sentinel", func() {
|
|||
MasterName: sentinelName,
|
||||
SentinelAddrs: []string{":" + sentinelPort},
|
||||
})
|
||||
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
|
||||
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
|
|
@ -15,7 +15,7 @@ var _ = Describe("Tx", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
client = redis.NewClient(redisOptions())
|
||||
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
|
||||
Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
|
Loading…
Reference in New Issue