当前位置: 首页>>代码示例>>Golang>>正文


Golang redis.Dial函数代码示例

本文整理汇总了Golang中github.com/mediocregopher/radix/v2/redis.Dial函数的典型用法代码示例。如果您正苦于以下问题:Golang Dial函数的具体用法?Golang Dial怎么用?Golang Dial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Dial函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: topDestinations

func topDestinations(rw http.ResponseWriter, req *http.Request) {

	client, err := redis.Dial("tcp", "localhost:6379")
	if err != nil {
		fmt.Println("Problem communicating to Redis...")
		log.Fatal(err)
	} else {
		defer client.Close()
	}

	response := client.Cmd("ZREVRANGE", "popularity", "0", "-1", "WITHSCORES")
	// here we create a byte buffer to construct the html response
	buffer := bytes.NewBufferString("<TABLE>")

	l, _ := response.List()
	for _, elemStr := range l {
		buffer.WriteString("<TR><TD>")
		buffer.WriteString(elemStr)
		buffer.WriteString("<TR><TD>")
	}
	buffer.WriteString("</TABLE>")

	p := loadTopPage(buffer.Bytes())
	renderTemplate(rw, "top", p)

}
开发者ID:ev46,项目名称:dnastat,代码行数:26,代码来源:server.go

示例2: newRedisDriver

func newRedisDriver(c *config) (*redisDriver, error) {
	r, err := redis.Dial("tcp", c.RedisAddress)
	if err != nil {
		return nil, err
	}
	return &redisDriver{c: r}, nil
}
开发者ID:nickwales,项目名称:proxym,代码行数:7,代码来源:driver.go

示例3: TestFailover

// Test a basic manual failover
func TestFailover(t *T) {
	s := getSentinel(t)
	sc, err := redis.Dial("tcp", "127.0.0.1:28000")
	require.Nil(t, err)

	k := randStr()

	c, err := s.GetMaster("test")
	require.Nil(t, err)
	require.Nil(t, c.Cmd("SET", k, "foo").Err)
	s.PutMaster("test", c)

	require.Nil(t, sc.Cmd("SENTINEL", "FAILOVER", "test").Err)

	c, err = s.GetMaster("test")
	require.Nil(t, err)
	foo, err := c.Cmd("GET", k).Str()
	require.Nil(t, err)
	assert.Equal(t, "foo", foo)
	require.Nil(t, c.Cmd("SET", k, "bar").Err)
	s.PutMaster("test", c)

	time.Sleep(10 * time.Second)
	require.Nil(t, sc.Cmd("SENTINEL", "FAILOVER", "test").Err)

	c, err = s.GetMaster("test")
	require.Nil(t, err)
	bar, err := c.Cmd("GET", k).Str()
	require.Nil(t, err)
	assert.Equal(t, "bar", bar)
	s.PutMaster("test", c)
}
开发者ID:MStoykov,项目名称:radix.v2,代码行数:33,代码来源:sentinel_test.go

示例4: TestPublishEvent

func TestPublishEvent(t *testing.T) {
	db := redisdb.New(dburl)
	if err := db.Connect(); err != nil {
		t.Fatalf("Failed to connect to redis: %s", err.Error())
	}

	c, err := redis.Dial("tcp", dburl)
	if err != nil {
		t.Fatalf("Failed to connect to redis2: %s", err.Error())
	}

	ps := pubsub.NewSubClient(c)
	ps.Subscribe("thechan")

	wg := sync.WaitGroup{}
	wg.Add(1)

	go func() {
		resp := ps.Receive()
		if resp.Message != "moar" {
			t.Errorf("Expected moar but got %s", resp.Message)
		}
		wg.Done()
	}()

	go func() {
		buf := bytes.NewBufferString("moar")
		if err := db.PublishEvent("thechan", buf); err != nil {
			t.Fatalf("Should have have errored publishing: %s", err.Error())
		}
	}()
	wg.Wait()
}
开发者ID:zclark,项目名称:wdead,代码行数:33,代码来源:integration_test.go

示例5: TestLuaEval

func TestLuaEval(t *T) {
	c1, err := redis.Dial("tcp", "127.0.0.1:6379")
	require.Nil(t, err)
	c2, err := cluster.New("127.0.0.1:7000")
	require.Nil(t, err)

	cs := []Cmder{c1, c2}

	for _, c := range cs {
		script, key, val := randTestScript()
		s, err := LuaEval(c, script, 1, key, val).Str()
		require.Nil(t, err)
		assert.Equal(t, "OK", s)

		// The second time the command will be hashed
		script, key, val = randTestScript()
		s, err = LuaEval(c, script, 1, key, val).Str()
		require.Nil(t, err)
		assert.Equal(t, "OK", s)

		s, err = c.Cmd("GET", key).Str()
		require.Nil(t, err)
		assert.Equal(t, val, s)
	}
}
开发者ID:MStoykov,项目名称:radix.v2,代码行数:25,代码来源:lua_test.go

示例6: NewRedisStorage

func NewRedisStorage(address string, db int, pass, mrshlerStr string, maxConns int) (*RedisStorage, error) {
	df := func(network, addr string) (*redis.Client, error) {
		client, err := redis.Dial(network, addr)
		if err != nil {
			return nil, err
		}
		if len(pass) != 0 {
			if err = client.Cmd("AUTH", pass).Err; err != nil {
				client.Close()
				return nil, err
			}
		}
		if db != 0 {
			if err = client.Cmd("SELECT", db).Err; err != nil {
				client.Close()
				return nil, err
			}
		}
		return client, nil
	}
	p, err := pool.NewCustom("tcp", address, maxConns, df)
	if err != nil {
		return nil, err
	}
	var mrshler Marshaler
	if mrshlerStr == utils.MSGPACK {
		mrshler = NewCodecMsgpackMarshaler()
	} else if mrshlerStr == utils.JSON {
		mrshler = new(JSONMarshaler)
	} else {
		return nil, fmt.Errorf("Unsupported marshaler: %v", mrshlerStr)
	}
	return &RedisStorage{db: p, ms: mrshler}, nil
}
开发者ID:bhepp,项目名称:cgrates,代码行数:34,代码来源:storage_redis.go

示例7: NewRedisProvider

func NewRedisProvider(network, addr, auth string, idleConns int) (*RedisProvider, error) {
	df := func(n, a string) (*redis.Client, error) {
		c, err := redis.Dial(n, a)
		if err != nil {
			return nil, err
		}

		if err = c.Cmd("AUTH", auth).Err; err != nil {
			c.Close()
			return nil, err
		}

		return c, nil
	}

	p, err := rPool.NewCustom(network, addr, idleConns, df)
	if err != nil {
		return nil, err
	}

	rp := &RedisProvider{
		Pool: p,
	}

	return rp, nil
}
开发者ID:codemodus,项目名称:sessctrl,代码行数:26,代码来源:provider_redis.go

示例8: setupRedis

func setupRedis() {

	c, err := redis.Dial("tcp", "localhost:6379")
	client = c
	if err != nil {
		//handle error
	}
}
开发者ID:gauravkm,项目名称:goshort,代码行数:8,代码来源:main.go

示例9: NewConnection

// NewConnection establishes a new connection to a Redis instance
func NewConnection(host, port string) *redis.Client {

	client, err := redis.Dial("tcp", host+":"+port)
	if err != nil {
		log.Println("Error while connecting:" + err.Error())
		return nil
	}
	return client
}
开发者ID:JKolios,项目名称:GoMarkov,代码行数:10,代码来源:myRedis.go

示例10: Connect

// Connect establishes a redis client connection.
func (db *DB) Connect() error {
	c, err := redis.Dial("tcp", db.addr)
	if err != nil {
		return err
	}

	db.client = c
	return nil
}
开发者ID:zclark,项目名称:wdead,代码行数:10,代码来源:redisdb.go

示例11: initConnection

func initConnection(connDetails connectionDetails) *redis.Client {
	// Connection Establishment

	client, err := redis.Dial("tcp", connDetails.host+":"+connDetails.port)
	if err != nil {
		fmt.Println("Error while connecting:" + err.Error())
		return nil
	}
	return client
}
开发者ID:JKolios,项目名称:GoRed,代码行数:10,代码来源:gored.go

示例12: pingRedis

// Redis is needed to run this test
func pingRedis() *redis.Client {

	redisClient, err := redis.Dial("tcp", getRedisHost())
	if err != nil {
		log.Warnln("Cannot find Redis (standalone) at 'localhost:6379'.")
		log.Infoln("Trying to connect to Redis sentinel ...")

		redisClient2, err2 := redis.Dial("tcp", getRedisSentinelHost())
		if err2 != nil {
			log.Infoln("Please start a local Redis or Redis sentinel.")
			log.Infoln("Please specify TEST_REDIS_HOST or TEST_REDIS_SENTINEL_HOST (and optionally TEST_REDIS_MASTER)")
			panic("Cannot find Redis server.")
		}
		log.Infof("Successfully connected to Redis Sentinel '%s'", redisClient2.Addr)
		return redisClient2
	}
	log.Infof("Successfully connected to Redis '%s'", redisClient.Addr)
	return redisClient
}
开发者ID:frosenberg,项目名称:go-cloud-stream,代码行数:20,代码来源:redis_test.go

示例13: init

func init() {
	flag.IntVar(&redisPort, "port", 0, "Port of the redis server.")
	flag.StringVar(&zset, "zset", "", "Name of the ZSET to store into redis.")

	flag.Parse()

	client, err = redis.Dial("tcp", fmt.Sprintf("localhost:%d", redisPort))
	if err != nil {
		log.Fatal("Couldn't open a connection to the Redis Server, please check that redis-server is running.")
	}
}
开发者ID:simar7,项目名称:crdt,代码行数:11,代码来源:crdt_redis_test.go

示例14: Client

func (r *rutil) Client() *redis.Client {
	if r.cli == nil {
		cli, err := redis.Dial("tcp", fmt.Sprintf("%s:%d", r.Host, r.Port))
		checkErr(err)
		if r.Auth != "" {
			res := cli.Cmd("AUTH", r.Auth)
			checkErr(res.Err)
		}
		r.cli = cli
	}
	return r.cli
}
开发者ID:slavaGanzin,项目名称:rutil,代码行数:12,代码来源:rutil.go

示例15: main

func main() {
	client, err := redis.Dial("tcp", "localhost:6379")
	if err != nil {
		log.Fatalf("Couldn't connect to Redis server")
	}
	defer client.Close()

	val, err := client.Cmd("ZCARD", "myxyht").Int64()
	if err != nil {
		log.Fatalf("Error retrieving value: %s", err)
	}
	fmt.Printf("value = %d", val)
}
开发者ID:rendon,项目名称:gosnippets,代码行数:13,代码来源:radix.go


注:本文中的github.com/mediocregopher/radix/v2/redis.Dial函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。