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


Golang redis.NewSynchClientWithSpec函數代碼示例

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


在下文中一共展示了NewSynchClientWithSpec函數的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: NewClient

func NewClient(t *testing.T) redis.Client {
	client, err := redis.NewSynchClientWithSpec(getTestConnSpec())
	if err != nil {
		t.Fatalf("TestGet - ", err)
	}
	return client
}
開發者ID:aaudis,項目名稱:GoRedisSession,代碼行數:7,代碼來源:support.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: 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

示例6: 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

示例7: 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

示例8: TestSyncClientConnectWithSpec

// Check that connection is actually passing passwords from spec
func TestSyncClientConnectWithSpec(t *testing.T) {
	spec := getTestConnSpec()

	client, err := redis.NewSynchClientWithSpec(spec)
	if err != nil {
		t.Fatalf("failed to create client with spec. Error: %s", err)
	} else if client == nil {
		t.Fatal("BUG: client is nil")
	}
	client.Quit()
}
開發者ID:aaudis,項目名稱:GoRedisSession,代碼行數:12,代碼來源:sync_test.go

示例9: TestSyncClientConnectWithBadSpec

// Check that connection is actually passing passwords from spec
// and catching AUTH ERRs.
func TestSyncClientConnectWithBadSpec(t *testing.T) {
	spec := getTestConnSpec()
	spec.Password("bad-password")
	client, expected := redis.NewSynchClientWithSpec(spec)
	if expected == nil {
		t.Error("BUG: Expected a RedisError")
	}
	if client != nil {
		t.Error("BUG: sync client reference on error MUST be nil")
	}
}
開發者ID:aaudis,項目名稱:GoRedisSession,代碼行數:13,代碼來源:sync_test.go

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: doOne

func doOne(cnt int) os.Error {

	var delta int64
	spec := redis.DefaultSpec().Db(13)

	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!")
	}

	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)

	client.Quit()
	return nil
}
開發者ID:evangineer,項目名稱:Go-Redis,代碼行數:48,代碼來源:synchclient.go

示例15: syncPublish

func syncPublish(spec *redis.ConnectionSpec, channel string, messageType string) {

	client, err := redis.NewSynchClientWithSpec(spec)
	if err != nil {
		log.Errorf("Failed to create the redis client : %s", err)
		os.Exit(1)
	}

	msg := []byte(fmt.Sprintf("{id : %s }", messageType))
	rcvCnt, err := client.Publish(channel, msg)
	if err != nil {
		log.Errorf("Error to publish the messge to the redis : %s", err)
	} else {
		log.Debugf("Message published to %d subscribers", rcvCnt)
	}

	client.Quit()
}
開發者ID:vassilux,項目名稱:vorimport,代碼行數:18,代碼來源:main.go


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