当前位置: 首页>>代码示例>>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;未经允许,请勿转载。