package redisrpc import ( "encoding/json" "log" "github.com/golang/protobuf/proto" ) //头部增加 func LLpush(key, field string, url ...string) (int64, error) { conn, _, err := Conn(url...) if err != nil { return 0, err } defer conn.Close() req := &LSetRequest{proto.String(key), proto.String(field), nil} res := &LSetResponse{} err = conn.LLpush(req, res) if err != nil { return 0, err } return res.GetRet(), nil } //尾部增加 func LRpush(key, field string, url ...string) (int64, error) { conn, _, err := Conn(url...) if err != nil { return 0, err } defer conn.Close() req := &LSetRequest{proto.String(key), proto.String(field), nil} res := &LSetResponse{} err = conn.LRpush(req, res) if err != nil { return 0, err } return res.GetRet(), nil } /** * 全部 */ func LRange(key string, start, stop int64, url ...string) ([]string, error) { conn, _, err := Conn(url...) if err != nil { return []string{}, err } defer conn.Close() req := &LRangeRequest{proto.String(key), proto.Int64(start), proto.Int64(stop), nil} res := &HGetListResponse{} err = conn.LRange(req, res) if err != nil { return []string{}, err } value := res.GetList() var list []string err = json.Unmarshal(value, &list) if err != nil { log.Println("json unmarshal error:", err) return []string{}, err } return list, nil } //长度 func LLen(key string, url ...string) (int64, error) { conn, _, err := Conn(url...) if err != nil { return 0, err } defer conn.Close() req := &LLenRequest{proto.String(key), nil} res := &LSetResponse{} err = conn.LLen(req, res) if err != nil { return 0, err } return res.GetRet(), nil }