Merge pull request #109 from go-redis/feature/client-pause

Add ClientPause command.
This commit is contained in:
Vladimir Mihailenco 2015-05-18 15:08:17 +03:00
commit c1033ead39
3 changed files with 37 additions and 6 deletions

View File

@ -1114,6 +1114,13 @@ func (c *commandable) ClientList() *StringCmd {
return cmd return cmd
} }
func (c *commandable) ClientPause(dur time.Duration) *BoolCmd {
cmd := NewBoolCmd("CLIENT", "PAUSE", formatMs(dur))
cmd._clusterKeyPos = 0
c.Process(cmd)
return cmd
}
func (c *commandable) ConfigGet(parameter string) *SliceCmd { func (c *commandable) ConfigGet(parameter string) *SliceCmd {
cmd := NewSliceCmd("CONFIG", "GET", parameter) cmd := NewSliceCmd("CONFIG", "GET", parameter)
cmd._clusterKeyPos = 0 cmd._clusterKeyPos = 0

View File

@ -19,6 +19,8 @@ var _ = Describe("Commands", func() {
BeforeEach(func() { BeforeEach(func() {
client = redis.NewClient(&redis.Options{ client = redis.NewClient(&redis.Options{
Addr: redisAddr, Addr: redisAddr,
ReadTimeout: 500 * time.Millisecond,
WriteTimeout: 500 * time.Millisecond,
PoolTimeout: 30 * time.Second, PoolTimeout: 30 * time.Second,
}) })
}) })
@ -75,6 +77,19 @@ var _ = Describe("Commands", func() {
Expect(r.Val()).To(Equal("")) Expect(r.Val()).To(Equal(""))
}) })
It("should ClientPause", func() {
err := client.ClientPause(time.Second).Err()
Expect(err).NotTo(HaveOccurred())
Consistently(func() error {
return client.Ping().Err()
}, "900ms").Should(HaveOccurred())
Eventually(func() error {
return client.Ping().Err()
}, "1s").ShouldNot(HaveOccurred())
})
It("should ConfigGet", func() { It("should ConfigGet", func() {
r := client.ConfigGet("*") r := client.ConfigGet("*")
Expect(r.Err()).NotTo(HaveOccurred()) Expect(r.Err()).NotTo(HaveOccurred())
@ -258,7 +273,7 @@ var _ = Describe("Commands", func() {
}) })
It("should Migrate", func() { It("should Migrate", func() {
migrate := client.Migrate("localhost", "6380", "key", 0, 0) migrate := client.Migrate("localhost", redisSecondaryPort, "key", 0, 0)
Expect(migrate.Err()).NotTo(HaveOccurred()) Expect(migrate.Err()).NotTo(HaveOccurred())
Expect(migrate.Val()).To(Equal("NOKEY")) Expect(migrate.Val()).To(Equal("NOKEY"))
@ -266,7 +281,7 @@ var _ = Describe("Commands", func() {
Expect(set.Err()).NotTo(HaveOccurred()) Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK")) Expect(set.Val()).To(Equal("OK"))
migrate = client.Migrate("localhost", "6380", "key", 0, 0) migrate = client.Migrate("localhost", redisSecondaryPort, "key", 0, 0)
Expect(migrate.Err()).To(MatchError("IOERR error or timeout writing to target instance")) Expect(migrate.Err()).To(MatchError("IOERR error or timeout writing to target instance"))
Expect(migrate.Val()).To(Equal("")) Expect(migrate.Val()).To(Equal(""))
}) })

View File

@ -17,7 +17,11 @@ import (
"gopkg.in/redis.v3" "gopkg.in/redis.v3"
) )
const redisAddr = ":6379" const (
redisPort = "6380"
redisAddr = ":" + redisPort
redisSecondaryPort = "6381"
)
const ( const (
sentinelName = "mymaster" sentinelName = "mymaster"
@ -27,7 +31,7 @@ const (
sentinelPort = "8126" sentinelPort = "8126"
) )
var sentinelMaster, sentinelSlave1, sentinelSlave2, sentinel *redisProcess var redisMain, sentinelMaster, sentinelSlave1, sentinelSlave2, sentinel *redisProcess
var cluster = &clusterScenario{ var cluster = &clusterScenario{
ports: []string{"8220", "8221", "8222", "8223", "8224", "8225"}, ports: []string{"8220", "8221", "8222", "8223", "8224", "8225"},
@ -39,6 +43,9 @@ var cluster = &clusterScenario{
var _ = BeforeSuite(func() { var _ = BeforeSuite(func() {
var err error var err error
redisMain, err = startRedis(redisPort)
Expect(err).NotTo(HaveOccurred())
sentinelMaster, err = startRedis(sentinelMasterPort) sentinelMaster, err = startRedis(sentinelMasterPort)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
@ -57,6 +64,8 @@ var _ = BeforeSuite(func() {
}) })
var _ = AfterSuite(func() { var _ = AfterSuite(func() {
Expect(redisMain.Close()).NotTo(HaveOccurred())
Expect(sentinel.Close()).NotTo(HaveOccurred()) Expect(sentinel.Close()).NotTo(HaveOccurred())
Expect(sentinelSlave1.Close()).NotTo(HaveOccurred()) Expect(sentinelSlave1.Close()).NotTo(HaveOccurred())
Expect(sentinelSlave2.Close()).NotTo(HaveOccurred()) Expect(sentinelSlave2.Close()).NotTo(HaveOccurred())