本文整理匯總了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
})
}
}
}
示例2: InitDB
func InitDB() {
var err error
Db, err = redis.Dial(NETWORK, Config.DB)
if err != nil {
panic(fmt.Sprintf("%v", err))
}
}
示例3: New
func New(url string) *RedisStore {
client, err := radix.Dial("tcp", url)
if err != nil {
panic(err)
}
return &RedisStore{client}
}
示例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)
}
示例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()
}
示例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
}
示例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
}
}
示例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, ×tamp)
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()
}
示例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)
}
示例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, ×tamp)
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))
}
示例11: SetupRedisConnection
func SetupRedisConnection() *redis.Client {
c, e := redis.Dial("tcp", ":6379")
if e != nil {
panic(e)
}
return c
}
示例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)
}
}
示例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)
}
}
示例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,
}
}
示例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,
}
}