当前位置: 首页>>代码示例>>Golang>>正文


Golang redis.Client类代码示例

本文整理汇总了Golang中github.com/mediocregopher/radix/v2/redis.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: AllBuckets

func AllBuckets(client *redis.Client) ([]*Bucket, error) {
	var ret []*Bucket

	keys, err := client.Cmd("KEYS", "*").Array()

	if err != nil {
		return nil, err
	}

	for _, key := range keys {
		keyval, err := key.Str()

		if err != nil {
			continue
		}

		b, err := GetBucket(client, keyval)

		if err != nil {
			continue
		}

		ret = append(ret, b)
	}

	return ret, nil
}
开发者ID:arsham-f,项目名称:Ceres,代码行数:27,代码来源:bucket.go

示例2: NewCustom

// NewCustom is like New except you can specify a DialFunc which will be
// used when creating new connections for the pool. The common use-case is to do
// authentication for new connections.
func NewCustom(network, addr string, size int, df DialFunc) (*Pool, error) {
	var client *redis.Client
	var err error
	pool := make([]*redis.Client, 0, size)
	for i := 0; i < size; i++ {
		client, err = df(network, addr)
		if err != nil {
			for _, client = range pool {
				client.Close()
			}
			pool = pool[0:]
			break
		}
		pool = append(pool, client)
	}
	p := Pool{
		Network: network,
		Addr:    addr,
		pool:    make(chan *redis.Client, len(pool)),
		df:      df,
	}
	for i := range pool {
		p.pool <- pool[i]
	}
	return &p, err
}
开发者ID:XUJiahua,项目名称:radix.v2,代码行数:29,代码来源:pool.go

示例3: scanHelper

func scanHelper(redisClient *redis.Client, pattern string, retCh chan string) error {
	cursor := "0"
	for {
		r := redisClient.Cmd("SCAN", cursor, "MATCH", pattern)
		if r.Err != nil {
			return r.Err
		}
		elems, err := r.Array()
		if err != nil {
			return err
		}

		results, err := elems[1].List()
		if err != nil {
			return err
		}

		for i := range results {
			retCh <- results[i]
		}

		if cursor, err = elems[0].Str(); err != nil {
			return err
		} else if cursor == "0" {
			return nil
		}
	}
}
开发者ID:mc0,项目名称:okq,代码行数:28,代码来源:db.go

示例4: luaHelper

func luaHelper(
	c *redis.Client, cmd string, numKeys int, args ...interface{},
) *redis.Resp {

	cmd = strings.ToUpper(cmd)
	l, ok := luaScripts[cmd]
	if !ok {
		return redis.NewResp(fmt.Errorf("unknown lua script: %s", cmd))
	}

	realArgs := make([]interface{}, 0, len(args)+2)
	realArgs = append(realArgs, l.hash, numKeys)
	realArgs = append(realArgs, args...)

	r, notLoaded := luaEvalSha(c, realArgs)
	if !notLoaded {
		return r
	}

	if err := c.Cmd("SCRIPT", "LOAD", l.script).Err; err != nil {
		return r
	}

	r, _ = luaEvalSha(c, realArgs)
	return r
}
开发者ID:mc0,项目名称:okq,代码行数:26,代码来源:db_lua.go

示例5: luaEvalSha

// Performs and EVALSHA with the given args, returning the reply and whether or
// not that reply is due to the script for that sha not being loaded yet
func luaEvalSha(c *redis.Client, args []interface{}) (*redis.Resp, bool) {
	r := c.Cmd("EVALSHA", args...)
	if r.Err != nil {
		if r.IsType(redis.AppErr) {
			return r, strings.HasPrefix(r.Err.Error(), "NOSCRIPT")
		}
	}
	return r, false
}
开发者ID:mc0,项目名称:okq,代码行数:11,代码来源:db_lua.go

示例6: Put

// Put returns a client back to the pool. If the pool is full the client is
// closed instead. If the client is already closed (due to connection failure or
// what-have-you) it will not be put back in the pool
func (p *Pool) Put(conn *redis.Client) {
	if conn.LastCritical == nil {
		select {
		case p.pool <- conn:
		default:
			conn.Close()
		}
	}
}
开发者ID:XUJiahua,项目名称:radix.v2,代码行数:12,代码来源:pool.go

示例7: pingRedis

// Pings redis to check whether the connection works. A connectTo...() methods needs
// to be called before.
func (t *Transport) pingRedis(client *redis.Client) error {

	resp := client.Cmd("PING")
	if resp.Err != nil {
		msg := fmt.Sprintf("Cannot connect to Redis host '%s': %s", t.Address, resp.Err)
		log.Fatal(msg)
		return resp.Err
	}

	return nil
}
开发者ID:frosenberg,项目名称:go-cloud-stream,代码行数:13,代码来源:redis.go

示例8: Put

// Put putss the connection back in its pool. To be used alongside any of the
// Get* methods once use of the redis.Client is done
func (c *Cluster) Put(conn *redis.Client) {
	c.callCh <- func(c *Cluster) {
		p := c.pools[conn.Addr]
		if p == nil {
			conn.Close()
			return
		}

		p.Put(conn)
	}
}
开发者ID:75912001,项目名称:radix.v2,代码行数:13,代码来源:cluster.go

示例9: Empty

// Empty removes and calls Close() on all the connections currently in the pool.
// Assuming there are no other connections waiting to be Put back this method
// effectively closes and cleans up the pool.
func (p *Pool) Empty() {
	var conn *redis.Client
	for {
		select {
		case conn = <-p.pool:
			conn.Close()
		default:
			return
		}
	}
}
开发者ID:XUJiahua,项目名称:radix.v2,代码行数:14,代码来源:pool.go

示例10: migrateTowns

func migrateTowns(townsDb *sql.DB, redisCli *redis.Client) {
	var townsCount int
	err := townsDb.QueryRow(`SELECT COUNT(*) FROM towns`).Scan(&townsCount)
	if err != nil {
		log.Fatalf("migrate: towns: %v\n", err)
	}

	rows, err := townsDb.Query(`SELECT id, name, name_tr, region_id,
                                       regional_center, latitude,
                                       longitude, zoom FROM towns`)
	if err != nil {
		log.Fatalf("migrate: towns: %v\n", err)
	}

	currentTownIdx := 1
	for rows.Next() {
		town := new(Town)
		var regionId uint32 = 0
		err = rows.Scan(&town.Id, &town.Name, &town.NameTr,
			&regionId, &town.RegionalCenter,
			&town.Latitude, &town.Longitude, &town.Zoom)
		if err != nil {
			log.Fatal(err)
		}

		if regionId != 0 {
			town.RegionId = new(uint32)
			*town.RegionId = regionId
		}

		jsonData, err := json.Marshal(town)
		if err != nil {
			log.Fatal(err)
		}

		err = redisCli.Cmd("SET", "town:"+strconv.FormatUint(uint64(town.Id), 10), string(jsonData)).Err
		if err != nil {
			log.Fatal(err)
		}

		err = redisCli.Cmd("GEOADD", "towns", town.Longitude, town.Latitude, town.Id).Err
		if err != nil {
			log.Fatal(err)
		}

		currentTownIdx++

		if currentTownIdx%500 == 0 {
			log.Printf("[%d/%d] Towns processed\n", currentTownIdx, townsCount)
		}
	}
	log.Printf("[%d/%d] Towns processed\n", townsCount, townsCount)
}
开发者ID:RasPavel,项目名称:android_cash_points,代码行数:53,代码来源:server_sqlite_to_redis.go

示例11: migrateBanks

func migrateBanks(banksDb *sql.DB, redisCli *redis.Client) {
	var banksCount int
	err := banksDb.QueryRow(`SELECT COUNT(*) FROM banks`).Scan(&banksCount)
	if err != nil {
		log.Fatalf("migrate: banks: %v", err)
	}

	rows, err := banksDb.Query(`SELECT id, name, name_tr, name_tr_alt, town,
                                       licence, rating, tel FROM banks`)
	if err != nil {
		log.Fatalf("migrate: banks: %v", err)
	}

	currentBankIdx := 1
	for rows.Next() {
		bank := new(Bank)
		var nameTr sql.NullString
		err = rows.Scan(&bank.Id, &bank.Name, &nameTr, &bank.NameTrAlt,
			&bank.Town, &bank.Licence, &bank.Rating, &bank.Tel)
		if err != nil {
			log.Fatal(err)
		}

		if nameTr.Valid {
			bank.NameTr = nameTr.String
		} else {
			bank.NameTr = ""
		}

		jsonData, err := json.Marshal(bank)
		if err != nil {
			log.Fatal(err)
		}

		err = redisCli.Cmd("SET", "bank:"+strconv.FormatUint(uint64(bank.Id), 10), string(jsonData)).Err
		if err != nil {
			log.Fatal(err)
		}

		err = redisCli.Cmd("SADD", "banks", bank.Id).Err
		if err != nil {
			log.Fatal(err)
		}

		currentBankIdx++

		if currentBankIdx%100 == 0 {
			log.Printf("[%d/%d] Banks processed\n", currentBankIdx, banksCount)
		}
	}
	log.Printf("[%d/%d] Banks processed\n", banksCount, banksCount)
}
开发者ID:RasPavel,项目名称:android_cash_points,代码行数:52,代码来源:server_sqlite_to_redis.go

示例12: CreateBucket

func CreateBucket(client *redis.Client, name string, length int) error {
	exists, err := client.Cmd("EXISTS", name).Int()

	if err != nil {
		return err
	}

	if exists == 1 {
		return errors.New("Bucket already exists")
	} else {
		return client.Cmd("SET", name, length, "NX").Err
	}
}
开发者ID:arsham-f,项目名称:Ceres,代码行数:13,代码来源:bucket.go

示例13: GetBucket

func GetBucket(client *redis.Client, name string) (*Bucket, error) {
	length, err := client.Cmd("GET", name).Str()
	if err != nil {
		return nil, err
	}

	b := new(Bucket)
	*b = Bucket{
		client,
		name,
		atoi(length),
	}

	return b, nil
}
开发者ID:arsham-f,项目名称:Ceres,代码行数:15,代码来源:bucket.go

示例14: migrateRegions

func migrateRegions(townsDb *sql.DB, redisCli *redis.Client) {
	var regionsCount int
	err := townsDb.QueryRow(`SELECT COUNT(*) FROM regions`).Scan(&regionsCount)
	if err != nil {
		log.Fatalf("migrate: regions: %v\n", err)
	}

	rows, err := townsDb.Query(`SELECT id, name, name_tr,
                                       latitude, longitude, zoom FROM regions`)
	if err != nil {
		log.Fatalf("migrate: regions: %v\n", err)
	}

	currentRegionIdx := 1
	for rows.Next() {
		region := new(Region)
		err = rows.Scan(&region.Id, &region.Name, &region.NameTr,
			&region.Latitude, &region.Longitude, &region.Zoom)
		if err != nil {
			log.Fatal(err)
		}

		jsonData, err := json.Marshal(region)
		if err != nil {
			log.Fatal(err)
		}

		err = redisCli.Cmd("SET", "region:"+strconv.FormatUint(uint64(region.Id), 10), string(jsonData)).Err
		if err != nil {
			log.Fatal(err)
		}

		err = redisCli.Cmd("GEOADD", "regions", region.Longitude, region.Latitude, region.Id).Err
		if err != nil {
			log.Fatal(err)
		}

		currentRegionIdx++

		if currentRegionIdx%500 == 0 {
			log.Printf("[%d/%d] Regions processed\n", currentRegionIdx, regionsCount)
		}
	}
	log.Printf("[%d/%d] Regions processed\n", regionsCount, regionsCount)
}
开发者ID:RasPavel,项目名称:android_cash_points,代码行数:45,代码来源:server_sqlite_to_redis.go

示例15: preloadRedisScriptSrc

func preloadRedisScriptSrc(redisCli *redis.Client, srcFilePath string) string {
	context := "preloadRedisScripts: " + srcFilePath

	buf := bytes.NewBuffer(nil)
	file, err := os.Open(srcFilePath)
	if err != nil {
		log.Fatalf("%s => %v\n", context, err)
	}
	io.Copy(buf, file)
	file.Close()
	src := string(buf.Bytes())

	response := redisCli.Cmd("SCRIPT", "LOAD", src)
	if response.Err != nil {
		log.Fatalf("%s => %v\n", context, response.Err)
	}
	scriptSha, err := response.Str()
	if err != nil {
		log.Fatalf("%s => %v\n", context, err)
	}
	return scriptSha
}
开发者ID:RasPavel,项目名称:android_cash_points,代码行数:22,代码来源:cash_points_srv.go


注:本文中的github.com/mediocregopher/radix/v2/redis.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。