|
|
@ -1,7 +1,6 @@ |
|
|
|
package redisrpc |
|
|
|
|
|
|
|
import ( |
|
|
|
"git.tetele.net/tgo/conf" |
|
|
|
"github.com/golang/protobuf/proto" |
|
|
|
) |
|
|
|
|
|
|
@ -10,15 +9,12 @@ import ( |
|
|
|
*/ |
|
|
|
func HGetString(key, field string, url ...string) (string, error) { |
|
|
|
|
|
|
|
var rpc_url string = "127.0.0.1:" + conf.REDIS_RPC_PORT |
|
|
|
if len(url) > 0 && url[0] != "" { |
|
|
|
rpc_url = url[0] |
|
|
|
} |
|
|
|
conn, _, err := Conn(url...) |
|
|
|
|
|
|
|
conn, _, err := DialRedisService("tcp", rpc_url) |
|
|
|
if err != nil { |
|
|
|
return "", err |
|
|
|
} |
|
|
|
|
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
req := &HGetRequest{proto.String(key), proto.String(field), nil} |
|
|
@ -33,3 +29,49 @@ func HGetString(key, field string, url ...string) (string, error) { |
|
|
|
|
|
|
|
return res.GetValue(), nil |
|
|
|
} |
|
|
|
|
|
|
|
//设置
|
|
|
|
func HSet(key, field, value string, url ...string) (uint64, error) { |
|
|
|
|
|
|
|
conn, _, err := Conn(url...) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return "", err |
|
|
|
} |
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
req := &HSetRequest{proto.String(key), proto.String(field), proto.String(value), nil} |
|
|
|
|
|
|
|
res := &HSetResponse{} |
|
|
|
|
|
|
|
err = conn.HSet(req, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return "", err |
|
|
|
} |
|
|
|
|
|
|
|
return res.GetRet(), nil |
|
|
|
} |
|
|
|
|
|
|
|
//删除
|
|
|
|
func HDel(key string, field string, url ...string) (uint64, error) { |
|
|
|
|
|
|
|
conn, _, err := Conn(url...) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
req := &HDelRequest{proto.String(key), proto.String(field), nil} |
|
|
|
|
|
|
|
res := &DelResponse{} |
|
|
|
|
|
|
|
err = conn.HDel(req, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
return res.GetRet(), nil |
|
|
|
} |