當前位置: 首頁>>代碼示例>>Golang>>正文


Golang redis.Dial函數代碼示例

本文整理匯總了Golang中github.com/fzzy/radix/redis.Dial函數的典型用法代碼示例。如果您正苦於以下問題:Golang Dial函數的具體用法?Golang Dial怎麽用?Golang Dial使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Dial函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RunTask

func (m *RedisEngine) RunTask() {
	client, err := redis.Dial("tcp", m.RedisServer)
	if err != nil {
		log.Println("redis connection err", err)
	}
	defer client.Close()
	for {
		select {
		case <-m.ExitChannel:
			return
		case request := <-m.CmdChannel:
			err = hystrix.Do("RedisCmd", func() error {
				reply := client.Cmd(request.Cmd, request.Args...)
				if reply.Err != nil {
					return reply.Err
				}
				request.ReplyChannel <- reply
				return nil
			}, func(error) error {
				if err != nil {
					log.Println(request.Cmd, request.Args, err)
				}
				client.Close()
				client, err = redis.Dial("tcp", m.RedisServer)
				return err
			})

		}
	}
}
開發者ID:datastream,項目名稱:metrictools,代碼行數:30,代碼來源:redisengine.go

示例2: InitDB

func InitDB() {
	var err error
	Db, err = redis.Dial(NETWORK, Config.DB)
	if err != nil {
		panic(fmt.Sprintf("%v", err))
	}
}
開發者ID:noahgoldman,項目名稱:dotaprofiles,代碼行數:7,代碼來源:db.go

示例3: New

func New(url string) *RedisStore {
	client, err := radix.Dial("tcp", url)
	if err != nil {
		panic(err)
	}
	return &RedisStore{client}
}
開發者ID:rlayte,項目名稱:toystore,代碼行數:7,代碼來源:redis.go

示例4: SetupTest

func (suite *HandlerSuite) SetupTest() {
	var err error
	df := func(network, addr string) (*redis.Client, error) {
		client, err := redis.Dial(network, addr)
		// fmt.Println("DIaling")
		if err != nil {
			return nil, err
		}
		err = client.Cmd("SELECT", 8).Err
		if err != nil {
			return nil, err
		}
		err = client.Cmd("FLUSHDB").Err
		if err != nil {
			return nil, err
		}
		return client, nil
	}
	redisPool, err = pool.NewCustomPool("tcp", redisURL, 1, df)
	if err != nil {
		panic(err)
	}

	c, err := redisPool.Get()
	errorHandler(err)
	defer redisPool.Put(c)
	SetDomain("xyz1234567890", "peterbe.com", c)

}
開發者ID:ateleshev,項目名稱:go-autocompeter,代碼行數:29,代碼來源:server_test.go

示例5: PushNode

func PushNode(settings *yaml.Yaml, message Message) {
	debug := settings.Get("debug").(bool)
	redis_connection := settings.Get("redis_connection").(string)
	redis_list := settings.Get("redis_list").(string)
	redis_db := settings.Get("redis_db").(int)

	t := time.Now()
	ts := t.Format("Mon Jan 2 15:04:05 -0700 MST 2006")
	rc, err := redis.Dial("tcp", redis_connection)
	if err != nil {
		fmt.Printf("[%s] ERROR Error received: %s\n", ts, err)
	}
	if debug {
		fmt.Printf("[%s] INFO Connection made to Redis server %s\n", ts, redis_connection)
	}
	r := rc.Cmd("SELECT", redis_db)
	if r.Err != nil {
		fmt.Printf("[%s] ERROR Error received: %s\n", ts, r.Err)
	} else {
		if debug {
			fmt.Printf("[%s] INFO Redis database selected: %d\n", ts, redis_db)
		}
	}
	j, errj := json.Marshal(message)
	if errj != nil {
		fmt.Printf("[%s] ERROR Error received: %s\n", ts, errj)
	}
	r = rc.Cmd("LPUSH", redis_list, j)
	rc.Close()
}
開發者ID:andrew-sledge,項目名稱:blueshift,代碼行數:30,代碼來源:blueshift.go

示例6: RedisClient

func RedisClient() *redis.Client {
	client, err := redis.Dial("tcp", redisURL())
	if err != nil {
		panic("Could not connect to redis on " + redisURL())
	}
	return client
}
開發者ID:wishpond-dev,項目名稱:canoe,代碼行數:7,代碼來源:redis_store.go

示例7: NewOutput

// Create a new Output for redis processing.
func NewOutput(u *url.URL) (io.Output, error) {
	if client, err := redis.Dial("tcp", u.Host); err == nil {
		return &Output{client: client}, nil
	} else {
		return nil, err
	}
}
開發者ID:d11wtq,項目名稱:logheap,代碼行數:8,代碼來源:redis.go

示例8: AssignmentsHandler

func AssignmentsHandler(w http.ResponseWriter, r *http.Request) {

	r.ParseForm()
	timeslot_id := r.FormValue("assignment[timeslot_id]")
	boat_id := r.FormValue("assignment[boat_id]")

	redisClient, _ := redis.Dial("tcp", "127.0.0.1:6379")

	data_ts, _ := redisClient.Cmd("GET", "ts:"+timeslot_id).Bytes()
	data_boat, _ := redisClient.Cmd("GET", "boat:"+boat_id).Bytes()

	var boat Boat
	json.Unmarshal(data_boat, &boat)

	var timestamp Timeslot
	json.Unmarshal(data_ts, &timestamp)

	timestamp.Boats = append(timestamp.Boats, boat)
	timestamp.Availability = max(timestamp.Availability, boat.Capacity)

	ts, _ := json.Marshal(timestamp)
	redisClient.Cmd("SET", "ts:"+timeslot_id, ts)
	redisClient.Cmd("SADD", "asmt:"+boat_id, "ts:"+timeslot_id)

	redisClient.Close()
}
開發者ID:prabhakarrajeev,項目名稱:Peek,代碼行數:26,代碼來源:main.go

示例9: TestReset

func TestReset(t *T) {
	// Simply initializing a cluster proves Reset works to some degree, since
	// NewCluster calls Reset
	cluster := getCluster(t)
	old7000 := cluster.clients["127.0.0.1:7000"]
	old7001 := cluster.clients["127.0.0.1:7001"]

	// We make a bogus client and add it to the cluster to prove that it gets
	// removed, since it's not needed
	client, err := redis.Dial("tcp", "127.0.0.1:6379")
	assert.Nil(t, err)
	cluster.clients["127.0.0.1:6379"] = client

	err = cluster.Reset()
	assert.Nil(t, err)

	// Prove that the bogus client is closed
	closedErr := errors.New("use of closed network connection")
	assert.Equal(t, closedErr, client.Cmd("PING").Err)

	// Prove that the remaining two addresses are still in clients, were not
	// reconnected, and still work
	assert.Equal(t, 2, len(cluster.clients))
	assert.Equal(t, old7000, cluster.clients["127.0.0.1:7000"])
	assert.Equal(t, old7001, cluster.clients["127.0.0.1:7001"])
	assert.NotNil(t, cluster.clients["127.0.0.1:7000"])
	assert.NotNil(t, cluster.clients["127.0.0.1:7001"])
	assert.Nil(t, cluster.Cmd("GET", "foo").Err)
	assert.Nil(t, cluster.Cmd("GET", "bar").Err)
}
開發者ID:qinguoan,項目名稱:rambo_golang,代碼行數:30,代碼來源:cluster_test.go

示例10: TimeslotHandler

func TimeslotHandler(w http.ResponseWriter, r *http.Request) {

	r.ParseForm()
	start_time, _ := strconv.ParseInt(r.FormValue("timeslot[start_time]"), 10, 0)
	dur, _ := strconv.ParseInt(r.FormValue("timeslot[duration]"), 10, 0)
	date := r.FormValue("date")
	var timeslot []byte

	redisClient, _ := redis.Dial("tcp", "127.0.0.1:6379")

	if len(date) == 0 {

		t1 := time.Unix(start_time, 0)
		dateKey := fmt.Sprintf("%d-%02d-%02d", t1.Year(), t1.Month(), t1.Day())

		v := &Timeslot{
			Id:             uuid.New(),
			Start_time:     start_time,
			Duration:       dur,
			Availability:   0,
			Customer_count: 0,
			Boats:          []Boat{},
		}
		timeslot, _ = json.Marshal(v)

		redisClient.Cmd("MULTI")
		redisClient.Cmd("SET", "ts:"+v.Id, timeslot)
		redisClient.Cmd("SADD", dateKey, "ts:"+v.Id)
		redisClient.Cmd("EXEC")
	} else {
		var ts []interface{}
		r := redisClient.Cmd("SMEMBERS", date)

		for i := range r.Elems {
			elemStr, _ := r.Elems[i].Str()
			data, _ := redisClient.Cmd("GET", elemStr).Bytes()

			var timestamp interface{}
			json.Unmarshal(data, &timestamp)

			bs := timestamp.(map[string]interface{})["Boats"]
			for i = 0; i < len(bs.([]interface{})); i++ {
				Id := (bs.([]interface{})[i]).(map[string]interface{})["Id"]
				delete((bs.([]interface{})[i]).(map[string]interface{}), "Id")
				delete((bs.([]interface{})[i]).(map[string]interface{}), "Name")
				delete((bs.([]interface{})[i]).(map[string]interface{}), "Capacity")
				bs.([]interface{})[i] = Id
			}
			ts = append(ts, timestamp)
		}
		timeslot, _ = json.Marshal(ts)
	}

	redisClient.Close()
	status := 200
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(status)
	w.Write([]byte(timeslot))
}
開發者ID:prabhakarrajeev,項目名稱:Peek,代碼行數:59,代碼來源:main.go

示例11: SetupRedisConnection

func SetupRedisConnection() *redis.Client {
	c, e := redis.Dial("tcp", ":6379")

	if e != nil {
		panic(e)
	}
	return c
}
開發者ID:jansichermann,項目名稱:redisinterface,代碼行數:8,代碼來源:redisinterface.go

示例12: Get

// Retrieves an available redis client. If there are none available it will
// create a new one on the fly
func (p *Pool) Get() (*redis.Client, error) {
	select {
	case conn := <-p.pool:
		return conn, nil
	default:
		return redis.Dial(p.network, p.addr)
	}
}
開發者ID:KushalP,項目名稱:radix,代碼行數:10,代碼來源:pool.go

示例13: initWebRedis

func initWebRedis() {
	var err error
	webDb, err = redis.Dial("tcp", "127.0.0.1:6379")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
開發者ID:heydabop,項目名稱:yaircb,代碼行數:8,代碼來源:web.go

示例14: NewRedisQueue

func NewRedisQueue(name string) *RedisQueue {
	client, err := redis.Dial("tcp", "localhost:6379")
	if err != nil {
		panic(err)
	}
	return &RedisQueue{
		c:    client,
		name: name,
	}
}
開發者ID:shitfSign,項目名稱:jq,代碼行數:10,代碼來源:redis_queue.go

示例15: RedisQueueManagerFactory

func RedisQueueManagerFactory(qfactory QueueFactory) QueueManager {
	client, err := redis.Dial("tcp", "localhost:6379")
	if err != nil {
		panic(err)
	}
	return &RedisQueueManager{
		c:        client,
		qfactory: qfactory,
	}
}
開發者ID:shitfSign,項目名稱:jq,代碼行數:10,代碼來源:redis_queue_manager.go


注:本文中的github.com/fzzy/radix/redis.Dial函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。