package redisrpc
|
|
|
|
import (
|
|
"github.com/golang/protobuf/proto"
|
|
)
|
|
|
|
/**
|
|
* 使用用户名查询
|
|
*/
|
|
func GetString(key string, url ...string) (string, error) {
|
|
|
|
conn, _, err := Conn(url...)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer conn.Close()
|
|
|
|
req := &GetRequest{proto.String(key), nil}
|
|
|
|
res := &GetStringResponse{}
|
|
|
|
err = conn.Get(req, res)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return res.GetValue(), nil
|
|
}
|
|
|
|
//设置
|
|
func Set(key, value string, ttl int64, url ...string) (string, error) {
|
|
|
|
conn, _, err := Conn(url...)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer conn.Close()
|
|
|
|
req := &SetRequest{proto.String(key), proto.String(value), proto.Int64(ttl), nil}
|
|
|
|
res := &SetResponse{}
|
|
|
|
err = conn.Set(req, res)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return res.GetRet(), nil
|
|
}
|
|
|
|
//删除
|
|
func Del(key string, url ...string) (int64, error) {
|
|
|
|
conn, _, err := Conn(url...)
|
|
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer conn.Close()
|
|
|
|
req := &DelRequest{proto.String(key), nil}
|
|
|
|
res := &DelResponse{}
|
|
|
|
err = conn.Del(req, res)
|
|
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return res.GetRet(), nil
|
|
}
|
|
|
|
func Exists(key string, url ...string)(int64, error){
|
|
conn, _, err := Conn(url...)
|
|
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer conn.Close()
|
|
|
|
req := &GetRequest{proto.String(key), nil}
|
|
|
|
res := &DelResponse{}
|
|
|
|
err = conn.Exists(req, res)
|
|
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return res.GetRet(), nil
|
|
}
|