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


Golang redis.DefaultSpec函數代碼示例

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


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

示例1: main

func main() {

	// create the client.  Here we are using a synchronous client.
	// Using the default ConnectionSpec, we are specifying the client to connect
	// to db 13 (e.g. SELECT 13), and a password of go-redis (e.g. AUTH go-redis)

	spec := redis.DefaultSpec().Db(13).Password("go-redis")
	client, e := redis.NewSynchClientWithSpec(spec)
	if e != nil {
		log.Println("failed to create the client", e)
		return
	}

	key := "examples/hello/user.name"
	value, e := client.Get(key)
	if e != nil {
		log.Println("error on Get", e)
		return
	}

	if value == nil {
		fmt.Printf("\nHello, don't believe we've met before!\nYour name? ")
		reader := bufio.NewReader(os.Stdin)
		user, _ := reader.ReadString(byte('\n'))
		if len(user) > 1 {
			user = user[0 : len(user)-1]
			value = []byte(user)
			client.Set(key, value)
		} else {
			fmt.Printf("vafanculo!\n")
			return
		}
	}
	fmt.Printf("Hey, ciao %s!\n", fmt.Sprintf("%s", value))
}
開發者ID:chronicaww,項目名稱:Go-Redis,代碼行數:35,代碼來源:ciao.go

示例2: RedisPush

func RedisPush(rawtokenstring string) int {
	spec := redis.DefaultSpec().Password("go-redis")
	client, e := redis.NewSynchClientWithSpec(spec)
	if e != nil {
		fmt.Println("error creating client for: ", e)
	}
	defer client.Quit()
	//pidString := strconv.Itoa(cmdI.Process.Pid)
	decryptedToken, err := jwt.Parse(rawtokenstring, func(token *jwt.Token) (interface{}, error) {
		return []byte(secretKey), nil
	})
	//fmt.Printf("token strings\nRaw: [%s]\nHeader: [%s]\nSignature: [%s]\n", decryptedToken.Raw, decryptedToken.Header, decryptedToken.Signature)

	//check if no error and valid token
	if err == nil && decryptedToken.Valid {
		fmt.Println("token is valid and not expired")

	} else {
		fmt.Println("Not valid: ", err)
		return 0
	}

	userID := decryptedToken.Claims["id"].(string)
	//fmt.Println("redis func userid: " + userID + "\n redis func raw: " + decryptedToken.Raw)
	var buf bytes.Buffer
	buf.Write([]byte(decryptedToken.Raw))
	e = client.Hset("clients/token", userID, buf.Bytes())
	//to retrieve token in redis-cli, do hget clients/tokens legacy
	if e != nil {
		fmt.Println("error writing to list")
		return 0
	}
	return 1
}
開發者ID:DontWorry33,項目名稱:thorium-go,代碼行數:34,代碼來源:launchprogram.go

示例3: benchTask

// Use a single redis.AsyncClient with specified number
// of workers to bench concurrent load on the async client
func benchTask(taskspec taskSpec, iterations int, workers int, printReport bool) (delta int64, err os.Error) {
	signal := make(chan int, workers) // Buffering optional but sensible.
	spec := redis.DefaultSpec().Db(13).Password("go-redis")
	client, e := redis.NewAsynchClientWithSpec(spec)
	if e != nil {
		log.Println("Error creating client for worker: ", e)
		return -1, e
	}
	//    defer client.Quit()        // will be deprecated soon
	defer client.RedisClient().Quit()

	t0 := time.Nanoseconds()
	for i := 0; i < workers; i++ {
		id := fmt.Sprintf("%d", i)
		go taskspec.task(id, signal, client, iterations)
	}
	for i := 0; i < workers; i++ {
		<-signal
	}
	delta = time.Nanoseconds() - t0
	//	for i := 0; i < workers; i++ {
	//		clients[i].Quit()
	//	}
	//
	if printReport {
		report("concurrent "+taskspec.name, delta, iterations*workers)
	}

	return
}
開發者ID:chronicaww,項目名稱:Go-Redis,代碼行數:32,代碼來源:asyncbench.go

示例4: getDefinedMethods

// Reflect over the methods defined in redis.Client
// and send back as []string (tolowercase)
// TOOD get rid of redundant code in switch
// (REVU: needs minor update to core code)
func getDefinedMethods(ctype clientType) (map[string]string, *error_) {

	var mmap = map[string]string{}

	spec := redis.DefaultSpec().Db(13).Password("go-redis")

	var e redis.Error
	var client interface{}

	switch ctype {
	case sync:
		client, e = redis.NewSynchClientWithSpec(spec)
	case async:
		client, e = redis.NewAsynchClientWithSpec(spec)
	}
	if e != nil {
		log.Println("ignoring - ", e)
	}
	if client == nil {
		return mmap, &error_{"client is nil", nil}
	} else {
		defer client.(redis.RedisClient).Quit()
	}

	tc := reflect.TypeOf(client)
	nm := tc.NumMethod()

	for i := 0; i < nm; i++ {
		m := tc.Method(i)
		mname := strings.ToLower(m.Name)
		mmap[mname] = mname
	}
	return mmap, nil
}
開發者ID:roolez,項目名稱:Go-Redis,代碼行數:38,代碼來源:compliance.go

示例5: spamChat1

func spamChat1(chanKey string) {
	fmt.Println("spamchat being called")
	spec := redis.DefaultSpec().Password("go-redis")
	client, e := redis.NewAsynchClientWithSpec(spec)
	if e != nil {
		fmt.Print("Error creating spam client for: ", e)
	}
	defer client.Quit()

	for i := 0; i < 1000000; i++ {
		var fr redis.FutureInt64
		//var fr2 redis.FutureBool
		var buf bytes.Buffer
		buf.Write([]byte("hello" + string(i)))
		bt := buf.Bytes()
		fr, e = client.Publish("chat", bt)
		//fmt.Println("we got past 2 publishes")
		if e != nil {
			fmt.Println("error in publishing: ", e)
		}
		_, e = client.Rpush("chatlog", bt)
		if e != nil {
			fmt.Println("error in storing list: ", e)
		}

		numRecieved, _ := fr.Get()
		//fmt.Println(numRecieved)
		//fr2.Get()
	}
}
開發者ID:DontWorry33,項目名稱:thorium-go,代碼行數:30,代碼來源:chat.go

示例6: NewRedisAsyncClient

func NewRedisAsyncClient() redis.AsyncClient {
	spec := redis.DefaultSpec().Db(0).Host("10.174.178.235")
	client, err := redis.NewAsynchClientWithSpec(spec)
	if err != nil {
		panic(err)
	}
	return client
}
開發者ID:rmoorman,項目名稱:web-bench,代碼行數:8,代碼來源:app-no-json.go

示例7: getclient

func getclient() redis.Client {
	spec := redis.DefaultSpec().Db(1)
	client, e := redis.NewSynchClientWithSpec(spec)
	if e != nil {
		log.Fatal(e)
	}
	return client
}
開發者ID:c00w,項目名稱:Calendar,代碼行數:8,代碼來源:database.go

示例8: Do

func Do(w http.ResponseWriter, req *http.Request) {
	taskid := req.URL.Query().Get("taskid") // 通知主刪除這個任務
	var spec *redis.ConnectionSpec = redis.DefaultSpec()
	ackip := utils.Cfg.GetString("redisIpACK")
	ackport := utils.Cfg.GetInt("redisIpACK")
	spec.Host(ackip)
	spec.Port(ackport)
	redis1.SyncPublish(spec, "ACK", taskid)
}
開發者ID:houzhenggang,項目名稱:ergate,代碼行數:9,代碼來源:service.go

示例9: NewLogger

/// 創建新的日誌記錄器.
///
/// @param servAddr redis服務器地址
/// @param servPort redis服務器端口
/// @param logLev 限製日誌輸出級別
/// @return 成功則返回日誌記錄器,同時error為nil.
func NewLogger(servAddr string, servPort int, logLev uint8) (*Logger, error) {
	spec := redis.DefaultSpec().Host(servAddr).Port(servPort)
	cli, err := redis.NewSynchClientWithSpec(spec)

	if nil != err {
		return nil, err
	}

	return &Logger{logLev, servAddr, servPort, cli, new(defaultFormatter)}, nil
}
開發者ID:liweisheng,項目名稱:server-framework,代碼行數:16,代碼來源:redis_log.go

示例10: _test_getDefConnSpec

// connection spec used in tests, using db 13 and password 'go-redis'.
// db 13 will be repeatedly flushed, as noted elsewhere.
func _test_getDefConnSpec() *redis.ConnectionSpec {

	host := "localhost"
	port := 6379
	db := 13
	password := "go-redis"

	connspec := redis.DefaultSpec().Host(host).Port(port).Db(db).Password(password)
	return connspec
}
開發者ID:aaudis,項目名稱:GoRedisSession,代碼行數:12,代碼來源:0data_test.go

示例11: NewReportInfo

func NewReportInfo(mid string, mt string, intv int16, reportAddr string, reportPort int) (*ReportInfo, error) {

	spec := redis.DefaultSpec().Host(reportAddr).Port(reportPort)
	cli, err := redis.NewSynchClientWithSpec(spec)

	if err != nil {
		return nil, err
	}

	return &ReportInfo{mid, mt, intv, cli}, nil
}
開發者ID:liweisheng,項目名稱:server-framework,代碼行數:11,代碼來源:reportInfo.go

示例12: makeConcurrentClients

func makeConcurrentClients(workers int) (clients []redis.Client, err error) {
	clients = make([]redis.Client, workers)
	for i := 0; i < workers; i++ {
		spec := redis.DefaultSpec().Db(13).Password("go-redis")
		client, e := redis.NewSynchClientWithSpec(spec)
		if e != nil {
			log.Println("Error creating client for worker: ", e)
			return nil, e
		}
		clients[i] = client
	}
	return
}
開發者ID:aaudis,項目名稱:GoRedisSession,代碼行數:13,代碼來源:gosynchclient.go

示例13: makeConcurrentClients

func makeConcurrentClients(workers int) (clients []redis.Client, err os.Error) {
    clients = make([]redis.Client, workers);
    for i := 0; i < workers; i++ {
		spec := redis.DefaultSpec().Db(13);
		client, e := redis.NewSynchClientWithSpec (spec);
		if e != nil {
			log.Stderr ("Error creating client for worker: ", e);
			return nil, e;
		}
		clients[i] = client;
    }
    return;
}
開發者ID:evangineer,項目名稱:Go-Redis,代碼行數:13,代碼來源:gosynchclient.go

示例14: doOne

func doOne(cnt int) error {

	var delta time.Duration
	spec := redis.DefaultSpec().Db(13).Password("go-redis")

	fmt.Printf("\n\n=== Bench synchclient ================ 1 Client -- %d opts --- \n", cnt)
	fmt.Println()

	client, e := redis.NewSynchClientWithSpec(spec)
	if e != nil {
		return onError("on NewSynchClient call: ", e)
	}
	if client == nil {
		return failedTest("NewSynchClient returned nil!")
	}
	//	defer client.Quit()   // will be deprecated soon
	defer client.RedisClient().Quit()

	client.Flushdb()

	delta = doPing(client, cnt)
	report("PING", delta, cnt)

	delta = doIncr(client, cnt)
	report("INCR", delta, cnt)

	delta = doSet(client, cnt)
	report("SET", delta, cnt)

	delta = doGet(client, cnt)
	report("GET", delta, cnt)

	delta = doSadd(client, cnt)
	report("SADD", delta, cnt)

	delta = doLpush(client, cnt)
	report("LPUSH", delta, cnt)

	delta = doRpush(client, cnt)
	report("RPUSH", delta, cnt)

	delta = doLpop(client, cnt)
	report("LPOP", delta, cnt)

	delta = doRpop(client, cnt)
	report("RPOP", delta, cnt)

	return nil
}
開發者ID:roolez,項目名稱:Go-Redis,代碼行數:49,代碼來源:synchclient.go

示例15: NewUniverse

func NewUniverse(dbNo int) *Universe {
	u := new(Universe)
	u.Players = make(map[int]*Player)
	u.Rooms = make(map[int]*Room)
	u.children = NewFlexContainer("Persistents", "TimeListeners")
	spec := redis.DefaultSpec().Db(dbNo)
	client, err := redis.NewSynchClientWithSpec(spec)
	if err != nil {
		panic(err)
	} else {
		u.dbConn = client
		u.Store = NewTinyDB(client)
	}
	return u
}
開發者ID:onewland,項目名稱:gomud,代碼行數:15,代碼來源:universe.go


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