12345678910111213141516171819202122232425262728293031323334 |
- package redis
- import (
- rd "github.com/gomodule/redigo/redis"
- "github.com/spf13/viper"
- "testing"
- )
- func TestRedisClusterPool(t *testing.T) {
- viper.SetDefault("redis.host", "127.0.0.1:6379")
- //viper.SetDefault("redis.host", "119.29.80.118:6379")
- //viper.SetDefault("redis.nodes", []string{"10.10.10.98:6379", "10.10.10.68:6379", "10.10.10.95:6379"})
- hub := NewHub()
- for i := 0; i < 500; i++ {
- _, err := hub.Do("LPUSH", "test_key", []byte("test"))
- if err != nil {
- println("push error:", err.Error())
- }
- }
- for i := 0; i < 100; i++ {
- go func() {
- data, err := rd.Bytes(hub.Do("RPOP", "test_key"))
- if err != nil {
- println("pop error:", err.Error())
- } else {
- println("pop received:", string(data))
- }
- }()
- }
- quit := make(chan bool)
- <-quit
- }
|