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


Golang redis.Conn類代碼示例

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


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

示例1: RedisSave

func (v *IRCLog) RedisSave(r redis.Conn) error {
	data, err := GobEncode(v)
	if err != nil {
		return err
	}
	_, err = r.Do("ZADD", v.GetKey(), v.LogId, data)
	return err
}
開發者ID:irctalk,項目名稱:irctalk-server,代碼行數:8,代碼來源:irc_struct.go

示例2: RedisRemoveWithConn

func RedisRemoveWithConn(r redis.Conn, v interface{}) (err error) {
	switch rm := v.(type) {
	case RedisRemover:
		err = rm.RedisRemove(r)
	case RedisInterface:
		_, err = r.Do("DEL", rm.GetKey())
	default:
		err = fmt.Errorf("Unsupported Type!")
	}
	return
}
開發者ID:irctalk,項目名稱:irctalk-server,代碼行數:11,代碼來源:redis.go

示例3: RedisLoadWithConn

func RedisLoadWithConn(r redis.Conn, v interface{}) (err error) {
	switch l := v.(type) {
	case RedisLoader:
		err = l.RedisLoad(r)
	case RedisInterface:
		data, err := redis.Bytes(r.Do("GET", l.GetKey()))
		if err != nil {
			return err
		}
		err = GobDecode(data, l)
	default:
		err = fmt.Errorf("Unsupperted Type!")
	}
	return
}
開發者ID:adrianuswarmenhoven,項目名稱:irctalk-server,代碼行數:15,代碼來源:redis.go

示例4: RedisSaveWithConn

func RedisSaveWithConn(r redis.Conn, v interface{}) (err error) {
	switch s := v.(type) {
	case RedisStorer:
		err = s.RedisSave(r)
	case RedisInterface:
		data, err := GobEncode(s)
		if err != nil {
			return err
		}
		_, err = r.Do("SET", s.GetKey(), data)
	default:
		err = fmt.Errorf("Unsupperted Type!")
	}
	return
}
開發者ID:adrianuswarmenhoven,項目名稱:irctalk-server,代碼行數:15,代碼來源:redis.go

示例5: RedisLoad

func (v *RedisSlice) RedisLoad(r redis.Conn) error {
	elemType := reflect.Indirect(reflect.New(v.eType))
	switch elemType.Interface().(type) {
	case RedisInterface:
		reply, err := redis.Values(r.Do("SORT", v.key, "GET", "*"))
		if err != nil {
			return err
		}
		newVal := reflect.MakeSlice(v.sType, len(reply), len(reply))
		for i, data := range reply {
			elem := reflect.New(v.eType.Elem())
			data, err := redis.Bytes(data, nil)
			if err != nil {
				return nil
			}
			err = GobDecode(data, elem.Interface())
			if err != nil {
				return err
			}
			newVal.Index(i).Set(elem)
		}
		v.slice.Set(newVal)
	default:
		reply, err := redis.Values(r.Do("SMEMBERS", v.key))
		if err != nil {
			return err
		}
		newVal := reflect.MakeSlice(v.sType, len(reply), len(reply))
		eType := v.eType
		if eType.Kind() == reflect.Ptr {
			eType = eType.Elem()
		}
		for i := 0; len(reply) > 0; i++ {
			elem := reflect.New(v.eType)
			reply, err = redis.Scan(reply, elem.Interface())
			if err != nil {
				return err
			}
			if eType.Kind() != reflect.Ptr {
				elem = elem.Elem()
			}
			newVal.Index(i).Set(elem)
		}
		v.slice.Set(newVal)
	}
	return nil
}
開發者ID:adrianuswarmenhoven,項目名稱:irctalk-server,代碼行數:47,代碼來源:redis.go

示例6: RedisRemove

func (v *RedisSlice) RedisRemove(r redis.Conn) error {
	if v.slice.Len() == 0 {
		return nil
	}
	keys := make([]interface{}, v.slice.Len()+1)
	keys[0] = v.key
	for i := 0; i < v.slice.Len(); i++ {
		switch ro := v.slice.Index(i).Interface().(type) {
		case RedisInterface:
			keys[i+1] = ro.GetKey()
			RedisRemoveWithConn(r, ro)
		default:
			keys[i+1] = ro
		}
	}
	_, err := r.Do("SREM", keys...)
	return err
}
開發者ID:irctalk,項目名稱:irctalk-server,代碼行數:18,代碼來源:redis.go


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