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