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


Golang Client.Cmd方法代码示例

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


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

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

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

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

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

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

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

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

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

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

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

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

示例12: allElos

func allElos(conn *redis.Client) map[string]float64 {
	result := conn.Cmd("HGETALL", "elo")
	if result.Err != nil {
		return nil
	}

	elos, err := result.Map()
	if err != nil {
		return nil
	}

	retval := make(map[string]float64)
	for player, elo := range elos {
		f, err := strconv.ParseFloat(elo, 64)
		if err != nil {
			conn.Cmd("HDEL", "elo", player)
		} else {
			retval[player] = f
		}
	}

	return retval
}
开发者ID:caeleel,项目名称:mmr,代码行数:23,代码来源:main.go

示例13: processSubImages

func processSubImages(conn *redis.Client, typeName string, key string) {
	var typeKey = "image:" + typeName + ":" + key
	keys, err := conn.Cmd("HKEYS", typeKey).List()
	if err != nil {
		log.Fatal("fetch all sub hash keys error")
	}
	for _, name := range keys {
		data, _ := conn.Cmd("HGET", typeKey, name).Bytes()
		fid := saveFileToFS(data)
		conn.Cmd("HSET", typeKey, name, fid)
	}
}
开发者ID:ququzone,项目名称:image-server,代码行数:12,代码来源:redis2seaweedfs.go

示例14: clientCmd

func (c *Cluster) clientCmd(
	client *redis.Client, cmd string, args []interface{}, ask bool,
	tried map[string]bool, haveReset bool,
) *redis.Resp {
	var err error
	var r *redis.Resp
	defer c.Put(client)

	if ask {
		r = client.Cmd("ASKING")
		ask = false
	}

	// If we asked and got an error, we continue on with error handling as we
	// would normally do. If we didn't ask or the ask succeeded we do the
	// command normally, and see how that goes
	if r == nil || r.Err == nil {
		r = client.Cmd(cmd, args...)
	}

	if err = r.Err; err == nil {
		return r
	}

	// At this point we have some kind of error we have to deal with. The above
	// code is what will be run 99% of the time and is pretty streamlined,
	// everything after this point is allowed to be hairy and gross

	haveTriedBefore := haveTried(tried, client.Addr)
	tried = justTried(tried, client.Addr)

	// Deal with network error
	if r.IsType(redis.IOErr) {
		// If this is the first time trying this node, try it again
		if !haveTriedBefore {
			if client, try2err := c.getConn("", client.Addr); try2err == nil {
				return c.clientCmd(client, cmd, args, false, tried, haveReset)
			}
		}
		// Otherwise try calling Reset() and getting a random client
		if !haveReset {
			if resetErr := c.Reset(); resetErr != nil {
				return errorRespf("Could not get cluster info: %s", resetErr)
			}
			client, getErr := c.getConn("", "")
			if getErr != nil {
				return errorResp(getErr)
			}
			return c.clientCmd(client, cmd, args, false, tried, true)
		}
		// Otherwise give up and return the most recent error
		return r
	}

	// Here we deal with application errors that are either MOVED or ASK
	msg := err.Error()
	moved := strings.HasPrefix(msg, "MOVED ")
	ask = strings.HasPrefix(msg, "ASK ")
	if moved || ask {
		_, addr := redirectInfo(msg)
		c.callCh <- func(c *Cluster) {
			select {
			case c.MissCh <- struct{}{}:
			default:
			}
		}

		// If we've already called Reset and we're getting MOVED again than the
		// cluster is having problems, likely telling us to try a node which is
		// not reachable. Not much which can be done at this point
		if haveReset {
			return errorRespf("Cluster doesn't make sense, %s might be gone", addr)
		}
		if resetErr := c.Reset(); resetErr != nil {
			return errorRespf("Could not get cluster info: %s", resetErr)
		}
		haveReset = true

		// At this point addr is whatever redis told us it should be. However,
		// if we can't get a connection to it we'll never actually mark it as
		// tried, resulting in an infinite loop. Here we mark it as tried
		// regardless of if it actually was or not
		tried = justTried(tried, addr)

		client, getErr := c.getConn("", addr)
		if getErr != nil {
			return errorResp(getErr)
		}
		return c.clientCmd(client, cmd, args, ask, tried, haveReset)
	}

	// It's a normal application error (like WRONG KEY TYPE or whatever), return
	// that to the client
	return r
}
开发者ID:75912001,项目名称:radix.v2,代码行数:95,代码来源:cluster.go

示例15: migrateCashpoints

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

	rows, err := cpDb.Query(`SELECT id, type, bank_id, town_id,
                                    longitude, latitude,
                                    address, address_comment,
                                    metro_name, free_access,
                                    main_office, without_weekend,
                                    round_the_clock, works_as_shop,
                                    schedule_general, tel, additional,
                                    rub, usd, eur, cash_in FROM cashpoints`)
	if err != nil {
		log.Fatalf("migrate: cashpoints: %v\n", err)
	}

	currentCashpointIndex := 1
	for rows.Next() {
		cp := new(CashPoint)
		err = rows.Scan(&cp.Id, &cp.Type, &cp.BankId, &cp.TownId,
			&cp.Longitude, &cp.Latitude,
			&cp.Address, &cp.AddressComment,
			&cp.MetroName, &cp.FreeAccess,
			&cp.MainOffice, &cp.WithoutWeekend,
			&cp.RoundTheClock, &cp.WorksAsShop,
			&cp.Schedule, &cp.Tel, &cp.Additional,
			&cp.Rub, &cp.Usd, &cp.Eur, &cp.CashIn)
		if err != nil {
			log.Fatal(err)
		}

		cashpointIdStr := strconv.FormatUint(uint64(cp.Id), 10)
		townIdStr := strconv.FormatUint(uint64(cp.TownId), 10)
		bankIdStr := strconv.FormatUint(uint64(cp.BankId), 10)

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

		err = redisCli.Cmd("SET", "cp:"+cashpointIdStr, string(jsonData)).Err
		if err != nil {
			log.Fatal(err)
		}

		err = redisCli.Cmd("SET", "cp:"+cashpointIdStr+":version", 1).Err
		if err != nil {
			log.Fatal(err)
		}

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

		err = redisCli.Cmd("SADD", "town:"+townIdStr+":cp", cp.Id).Err
		if err != nil {
			log.Fatal(err)
		}

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

		currentCashpointIndex++

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


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