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


Golang redis.Setex函數代碼示例

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


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

示例1: GetAllCdnFiles

// GetAllCdnFiles Retrieves all CdnFiles
func GetAllCdnFiles() (cs CdnFiles, err error) {
	data, err := redis.Get(AllCdnFilesRedisKey)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &cs)
		return
	}
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return
	}
	defer db.Close()
	stmt, err := db.Prepare(getAllCdnFiles)
	if err != nil {
		return
	}
	defer stmt.Close()
	rows, err := stmt.Query()
	if err != nil {
		return
	}

	ch := make(chan CdnFiles)
	go populateCdns(rows, ch)
	cs = <-ch
	if len(cs) == 0 {
		err = sql.ErrNoRows
		return
	}
	go redis.Setex(AllCdnFilesRedisKey, cs, 86400)
	return
}
開發者ID:ninnemana,項目名稱:API,代碼行數:32,代碼來源:video.go

示例2: Get

// Retrieves a base video file. This does not grab all the associated channels or CDN files.
func (v *Video) Get() error {
	redis_key := "video:" + strconv.Itoa(v.ID)
	data, err := redis.Get(redis_key)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &v)
		return err
	}
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	stmt, err := db.Prepare(getVideo)
	if err != nil {
		return err
	}
	defer stmt.Close()
	row := stmt.QueryRow(v.ID)

	ch := make(chan Video)

	go populateVideo(row, ch)
	*v = <-ch
	if v != nil {
		go redis.Setex(redis_key, *v, redis.CacheTimeout)
	}
	return err
}
開發者ID:ninnemana,項目名稱:API,代碼行數:29,代碼來源:video.go

示例3: Update

func (p *Price) Update() error {
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	stmt, err := tx.Prepare(updatePrice)

	_, err = stmt.Exec(p.CustID, p.PartID, p.Price, p.IsSale, p.SaleStart, p.SaleEnd, p.ID)
	if err != nil {
		tx.Rollback()
		return err
	}
	err = tx.Commit()
	if err != nil {
		return err
	}
	go redis.Setex("price:"+strconv.Itoa(p.ID), p, 86400)
	go redis.Delete(fmt.Sprintf("prices:part:%d", strconv.Itoa(p.PartID)))
	go redis.Delete(fmt.Sprintf("customers:prices:%d", strconv.Itoa(p.CustID)))
	return nil
}
開發者ID:ninnemana,項目名稱:API,代碼行數:26,代碼來源:price.go

示例4: GetLeads

func GetLeads(pageStr, resultsStr string, dtx *apicontext.DataContext) (pagination.Objects, error) {
	var err error
	var fs []interface{}
	var l pagination.Objects
	redis_key := "news:leads" + ":" + dtx.BrandString
	data, err := redis.Get(redis_key)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &l)
		return l, err
	}
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return l, err
	}
	defer db.Close()

	stmt, err := db.Prepare(getLeads)
	if err != nil {
		return l, err
	}
	defer stmt.Close()

	res, err := stmt.Query(dtx.APIKey, dtx.BrandID, dtx.BrandID)
	for res.Next() {
		var f News
		res.Scan(&f.Lead)
		fs = append(fs, f)
	}
	defer res.Close()
	l = pagination.Paginate(pageStr, resultsStr, fs)

	go redis.Setex(redis_key, l, 86400)
	return l, err
}
開發者ID:ninnemana,項目名稱:API,代碼行數:34,代碼來源:news_model.go

示例5: GetAll

func GetAll(dtx *apicontext.DataContext) (Newses, error) {
	var fs Newses
	var err error
	redis_key := "news" + ":" + dtx.BrandString
	data, err := redis.Get(redis_key)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &fs)
		return fs, err
	}

	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return fs, err
	}
	defer db.Close()

	stmt, err := db.Prepare(getAll)
	if err != nil {
		return fs, err
	}
	defer stmt.Close()

	res, err := stmt.Query(dtx.APIKey, dtx.BrandID, dtx.BrandID)
	for res.Next() {
		n, err := scanItem(res)
		if err == nil {
			fs = append(fs, n)
		}
	}
	defer res.Close()

	go redis.Setex(redis_key, fs, 86400)
	return fs, nil
}
開發者ID:ninnemana,項目名稱:API,代碼行數:34,代碼來源:news_model.go

示例6: GetAllWebPropertyNotes

// gets all of the web property notes - rarely called.
func GetAllWebPropertyNotes(dtx *apicontext.DataContext) (WebPropertyNotes, error) {
	var ws WebPropertyNotes
	var err error

	redis_key := "webpropertynotes:" + dtx.BrandString
	data, err := redis.Get(redis_key)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &ws)
		if err == nil {
			return ws, err
		}
	}
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return ws, err
	}
	defer db.Close()

	stmt, err := db.Prepare(getAllWebPropertyNotes)
	if err != nil {
		return ws, err
	}
	defer stmt.Close()

	res, err := stmt.Query(dtx.APIKey, dtx.BrandID, dtx.BrandID)
	for res.Next() {
		var w WebPropertyNote
		res.Scan(&w.ID, &w.WebPropID, &w.Text, &w.DateAdded)
		ws = append(ws, w)
	}
	go redis.Setex(redis_key, ws, 86400)
	return ws, err
}
開發者ID:ninnemana,項目名稱:API,代碼行數:34,代碼來源:webProperty_model.go

示例7: GetAllPrices

func GetAllPrices() (Prices, error) {
	var ps Prices
	var err error
	data, err := redis.Get(allPricesRedisKey)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &ps)
		return ps, err
	}

	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return ps, err
	}
	defer db.Close()

	stmt, err := db.Prepare(getPrices)
	if err != nil {
		return ps, err
	}
	defer stmt.Close()
	res, err := stmt.Query()
	for res.Next() {
		var p Price
		err = res.Scan(&p.ID, &p.CustID, &p.PartID, &p.Price, &p.IsSale, &p.SaleStart, &p.SaleEnd)
		ps = append(ps, p)
	}
	defer res.Close()
	go redis.Setex(allPricesRedisKey, ps, 86400)
	return ps, nil
}
開發者ID:ninnemana,項目名稱:API,代碼行數:30,代碼來源:price.go

示例8: Get

func (n *News) Get(dtx *apicontext.DataContext) error {
	var err error

	redis_key := "news:" + strconv.Itoa(n.ID) + ":" + dtx.BrandString
	data, err := redis.Get(redis_key)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &n)
		return err
	}
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()

	stmt, err := db.Prepare(getNews)
	if err != nil {
		return err
	}
	defer stmt.Close()

	row := stmt.QueryRow(n.ID, dtx.APIKey, dtx.BrandID, dtx.BrandID)
	item, err := scanItem(row)
	if err != nil {
		return err
	}

	n.copy(item)

	go redis.Setex(redis_key, n, 86400)

	return nil
}
開發者ID:ninnemana,項目名稱:API,代碼行數:33,代碼來源:news_model.go

示例9: Get

func (p *Price) Get() error {
	redis_key := "price:" + strconv.Itoa(p.ID)
	data, err := redis.Get(redis_key)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &p)
		return err
	}

	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()

	stmt, err := db.Prepare(getPrice)
	if err != nil {
		return err
	}
	defer stmt.Close()
	err = stmt.QueryRow(p.ID).Scan(&p.ID, &p.CustID, &p.PartID, &p.Price, &p.IsSale, &p.SaleStart, &p.SaleEnd)
	if err != nil {
		return err
	}

	go redis.Setex(redis_key, p, 86400)
	return nil
}
開發者ID:ninnemana,項目名稱:API,代碼行數:27,代碼來源:price.go

示例10: GetPricesByPart

func GetPricesByPart(partID int) (Prices, error) {
	var ps Prices
	redis_key := "prices:part:" + strconv.Itoa(partID)
	data, err := redis.Get(redis_key)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &ps)
		return ps, err
	}

	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return ps, err
	}
	defer db.Close()

	stmt, err := db.Prepare(getPricesByPart)
	if err != nil {
		return ps, err
	}
	defer stmt.Close()
	res, err := stmt.Query(partID)
	for res.Next() {
		var p Price
		res.Scan(&p.ID, &p.CustID, &p.PartID, &p.Price, &p.IsSale, &p.SaleStart, &p.SaleEnd)
		ps = append(ps, p)
	}
	go redis.Setex(redis_key, ps, 86400)
	return ps, nil
}
開發者ID:ninnemana,項目名稱:API,代碼行數:29,代碼來源:price.go

示例11: GetPricesByCustomer

func (c *Customer) GetPricesByCustomer() (CustomerPrices, error) {
	var cps CustomerPrices
	redis_key := "customers:prices:" + strconv.Itoa(c.Id)
	data, err := redis.Get(redis_key)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &cps)
		return cps, err
	}

	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return cps, err
	}
	defer db.Close()

	stmt, err := db.Prepare(getPricesByCustomer)
	if err != nil {
		return cps, err
	}
	defer stmt.Close()
	res, err := stmt.Query(c.Id)
	for res.Next() {
		var p Price
		res.Scan(&p.ID, &p.CustID, &p.PartID, &p.Price, &p.IsSale, &p.SaleStart, &p.SaleEnd)

		cps.Prices = append(cps.Prices, p)
	}
	go redis.Setex(redis_key, cps, 86400)
	return cps, err
}
開發者ID:ninnemana,項目名稱:API,代碼行數:30,代碼來源:price.go

示例12: GetCdnFiles

// GetCdnFiles Gets all of the CdnFiles for the specific video.
func (v *Video) GetCdnFiles() (cdns CdnFiles, err error) {
	redis_key := "video:cdnFiles:" + strconv.Itoa(v.ID)
	data, err := redis.Get(redis_key)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &cdns)
		return
	}
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return
	}
	defer db.Close()
	stmt, err := db.Prepare(getVideoCdns)
	if err != nil {
		return
	}
	defer stmt.Close()
	rows, err := stmt.Query(v.ID)
	if err != nil {
		return
	}

	ch := make(chan CdnFiles)
	go populateCdns(rows, ch)
	cdns = <-ch

	if cdns != nil {
		go redis.Setex(redis_key, cdns, redis.CacheTimeout)
	}

	return
}
開發者ID:ninnemana,項目名稱:API,代碼行數:33,代碼來源:video.go

示例13: Create

func (p *Price) Create() error {
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()
	tx, err := db.Begin()
	if err != nil {
		return err
	}

	stmt, err := tx.Prepare(createPrice)
	res, err := stmt.Exec(p.CustID, p.PartID, p.Price, p.IsSale, p.SaleStart, p.SaleEnd)
	if err != nil {
		tx.Rollback()
		return err
	}
	id, err := res.LastInsertId()
	p.ID = int(id)
	if err != nil {
		tx.Rollback()
		return err
	}
	err = tx.Commit()
	if err != nil {
		return err
	}
	go redis.Delete(allPricesRedisKey)
	go redis.Setex("price:"+strconv.Itoa(p.ID), p, 86400)
	return nil
}
開發者ID:ninnemana,項目名稱:API,代碼行數:31,代碼來源:price.go

示例14: GetAllWebPropertyRequirements

// Gets All Web Property Requirements
func GetAllWebPropertyRequirements(dtx *apicontext.DataContext) (WebPropertyRequirements, error) {
	var ws WebPropertyRequirements
	var err error

	redis_key := "webpropertyrequirements:" + dtx.BrandString
	data, err := redis.Get(redis_key)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &ws)
		if err == nil {
			return ws, err
		}
	}
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return ws, err
	}
	defer db.Close()

	stmt, err := db.Prepare(getAllWebPropertyRequirements)
	if err != nil {
		return ws, err
	}
	defer stmt.Close()

	res, err := stmt.Query(dtx.APIKey, dtx.BrandID, dtx.BrandID)
	for res.Next() {
		var w WebPropertyRequirement
		var reqType, req *string
		var comp *bool
		var wpid *int
		err = res.Scan(
			&w.ID,
			&w.RequirementID,
			&reqType,
			&req,
			&comp,
			&wpid,
		)
		if err != nil {
			return ws, err
		}
		if reqType != nil {
			w.ReqType = *reqType
		}
		if req != nil {
			w.Requirement = *req
		}
		if comp != nil {
			w.Compliance = *comp
		}
		if wpid != nil {
			w.WebPropID = *wpid
		}
		ws = append(ws, w)
	}
	go redis.Setex(redis_key, ws, 86400)
	return ws, err
}
開發者ID:ninnemana,項目名稱:API,代碼行數:59,代碼來源:webProperty_model.go

示例15: GetVideos

func (p *Part) GetVideos(dtx *apicontext.DataContext) error {
	redis_key := fmt.Sprintf("part:%d:videos:%s", p.ID, dtx.BrandString)

	data, err := redis.Get(redis_key)
	if err == nil && len(data) > 0 {
		if err = json.Unmarshal(data, &p.Videos); err != nil {
			return nil
		}
	}

	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return err
	}
	defer db.Close()

	qry, err := db.Prepare(partVideoStmt)
	if err != nil {
		return err
	}
	defer qry.Close()

	rows, err := qry.Query(p.ID)
	if err != nil {
		return err
	}

	var videos []PartVideo
	for rows.Next() {
		var v PartVideo
		var icon *string
		err = rows.Scan(
			&v.YouTubeVideoId,
			&v.Type,
			&v.IsPrimary,
			&icon)
		if err != nil {
			continue
		}

		v.TypeIcon, _ = url.Parse(*icon)
		videos = append(videos, v)
	}
	defer rows.Close()

	go redis.Setex(redis_key, p.Videos, redis.CacheTimeout)

	return nil
}
開發者ID:ninnemana,項目名稱:API,代碼行數:49,代碼來源:videos.go


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