forked from mirror/redis
Merge branch 'master' of github.com:go-redis/redis
This commit is contained in:
commit
92c3b30cb0
|
@ -343,11 +343,7 @@ func ExamplePubSub() {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Consume messages.
|
// Consume messages.
|
||||||
for {
|
for msg := range ch {
|
||||||
msg, ok := <-ch
|
|
||||||
if !ok {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
fmt.Println(msg.Channel, msg.Payload)
|
fmt.Println(msg.Channel, msg.Payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ type Options struct {
|
||||||
// Default is 5 seconds.
|
// Default is 5 seconds.
|
||||||
DialTimeout time.Duration
|
DialTimeout time.Duration
|
||||||
// Timeout for socket reads. If reached, commands will fail
|
// Timeout for socket reads. If reached, commands will fail
|
||||||
// with a timeout instead of blocking.
|
// with a timeout instead of blocking. Use value -1 for no timeout and 0 for default.
|
||||||
// Default is 3 seconds.
|
// Default is 3 seconds.
|
||||||
ReadTimeout time.Duration
|
ReadTimeout time.Duration
|
||||||
// Timeout for socket writes. If reached, commands will fail
|
// Timeout for socket writes. If reached, commands will fail
|
||||||
|
|
|
@ -5,6 +5,7 @@ package redis
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseURL(t *testing.T) {
|
func TestParseURL(t *testing.T) {
|
||||||
|
@ -92,3 +93,27 @@ func TestParseURL(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test ReadTimeout option initialization, including special values -1 and 0.
|
||||||
|
// And also test behaviour of WriteTimeout option, when it is not explicitly set and use
|
||||||
|
// ReadTimeout value.
|
||||||
|
func TestReadTimeoutOptions(t *testing.T) {
|
||||||
|
testDataInputOutputMap := map[time.Duration]time.Duration{
|
||||||
|
-1: 0 * time.Second,
|
||||||
|
0: 3 * time.Second,
|
||||||
|
1: 1 * time.Nanosecond,
|
||||||
|
3: 3 * time.Nanosecond,
|
||||||
|
}
|
||||||
|
|
||||||
|
for in, out := range testDataInputOutputMap {
|
||||||
|
o := &Options{ReadTimeout: in}
|
||||||
|
o.init()
|
||||||
|
if o.ReadTimeout != out {
|
||||||
|
t.Errorf("got %d instead of %d as ReadTimeout option", o.ReadTimeout, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.WriteTimeout != o.ReadTimeout {
|
||||||
|
t.Errorf("got %d instead of %d as WriteTimeout option", o.WriteTimeout, o.ReadTimeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -153,13 +153,13 @@ func (c *SentinelClient) PSubscribe(channels ...string) *PubSub {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SentinelClient) GetMasterAddrByName(name string) *StringSliceCmd {
|
func (c *SentinelClient) GetMasterAddrByName(name string) *StringSliceCmd {
|
||||||
cmd := NewStringSliceCmd("SENTINEL", "get-master-addr-by-name", name)
|
cmd := NewStringSliceCmd("sentinel", "get-master-addr-by-name", name)
|
||||||
c.Process(cmd)
|
c.Process(cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SentinelClient) Sentinels(name string) *SliceCmd {
|
func (c *SentinelClient) Sentinels(name string) *SliceCmd {
|
||||||
cmd := NewSliceCmd("SENTINEL", "sentinels", name)
|
cmd := NewSliceCmd("sentinel", "sentinels", name)
|
||||||
c.Process(cmd)
|
c.Process(cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue