Merge pull request !74 from bandl/refactor-struct-proto
This commit is contained in:
bandl 2021-10-23 16:42:16 +00:00 committed by Gitee
commit ebfa948421
17 changed files with 1645 additions and 1693 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,85 +0,0 @@
// Code generated by gen-struct. DO NOT EDIT.
// make gen-struct generated
package structure
const (
DEFAULT_KEY = iota
STRING_X
LIST_X
)
const (
DEFAULT_COMM = iota
SET
GET
ADD
REDUCE
SETBIT
GETBIT
GETRANGE
GETSET
STRLEN
SETNX
LINDEX
LLEN
LPOP
LPUSH
LPUSHX
LRANGE
LREM
LSET
RPOP
LTRIM
RPUSH
RPUSHX
)
var CommKeyString = map[string]int{"set": STRING_X,
"get": STRING_X,
"add": STRING_X,
"reduce": STRING_X,
"setbit": STRING_X,
"getbit": STRING_X,
"getrange": STRING_X,
"getset": STRING_X,
"strlen": STRING_X,
"setnx": STRING_X,
"lindex": LIST_X,
"llen": LIST_X,
"lpop": LIST_X,
"lpush": LIST_X,
"lpushx": LIST_X,
"lrange": LIST_X,
"lrem": LIST_X,
"lset": LIST_X,
"rpop": LIST_X,
"ltrim": LIST_X,
"rpush": LIST_X,
"rpushx": LIST_X,
}
var CommKey = map[int]int{SET: STRING_X,
GET: STRING_X,
ADD: STRING_X,
REDUCE: STRING_X,
SETBIT: STRING_X,
GETBIT: STRING_X,
GETRANGE: STRING_X,
GETSET: STRING_X,
STRLEN: STRING_X,
SETNX: STRING_X,
LINDEX: LIST_X,
LLEN: LIST_X,
LPOP: LIST_X,
LPUSH: LIST_X,
LPUSHX: LIST_X,
LRANGE: LIST_X,
LREM: LIST_X,
LSET: LIST_X,
RPOP: LIST_X,
LTRIM: LIST_X,
RPUSH: LIST_X,
RPUSHX: LIST_X,
}

View File

@ -1,29 +0,0 @@
// Code generated by gen-struct. DO NOT EDIT.
// make gen-struct generated
package structure
import "gitee.com/timedb/wheatCache/pkg/proto"
type KeyBaseInterface interface {
SizeByte() int64
// RollBack TODO 事务相关, V2 实现
RollBack() error
// Begin 事务相关, V2 实现
Begin() error
// Comment 事务相关, V2 实现
Comment() error
Encode() ([]byte, error)
}
{% for dict_item in Data %}
{% for key, value in dict_item.items() %}
type {{key}}Interface interface{
KeyBaseInterface
{% for val in value -%}
{{val}}(*proto.{{val}}Request) (*proto.{{val}}Response, error)
{% endfor %}
}
{% endfor -%}
{%- endfor %}

View File

@ -1,28 +0,0 @@
# 这里定义结构体的支持的命令, 以后也许会添加结构体的命令验证
# 定义结构体名称以及方法使, 方法全部小写,结构体名称全部大写且结构体名称需要加上 _X, 如 LIST_X
STRING_X:
- set
- get
- add
- reduce
- setbit
- getbit
- getrange
- getset
- strlen
- setnx
LIST_X:
- lindex
- llen
- lpop
- lpush
- lpushx # 列表不存在则不插入
- lrange
- lrem
- lset
- rpop
- ltrim # 对列表进行切片
- rpush
- rpushx # 对已经存在的列表尾插

View File

@ -2,108 +2,108 @@ syntax = "proto3";
import "base.proto"; import "base.proto";
option go_package = "pkg/proto"; option go_package = "pkg/proto";
message LindexRequest { message LIndexRequest {
BaseKey key = 1; BaseKey key = 1;
int32 index = 2; int32 index = 2;
} }
message LindexResponse { message LIndexResponse {
string result = 1; string result = 1;
} }
message LlenRequest { message LLenRequest {
BaseKey key = 1; BaseKey key = 1;
} }
message LlenResponse { message LLenResponse {
int32 length = 1; int32 length = 1;
} }
message LpopRequest { message LPopRequest {
BaseKey key = 1; BaseKey key = 1;
int32 count = 2; int32 count = 2;
} }
message LpopResponse { message LPopResponse {
repeated string results = 1; repeated string results = 1;
} }
message LpushRequest { message LPushRequest {
BaseKey key = 1; BaseKey key = 1;
repeated string values = 2; repeated string values = 2;
} }
message LpushResponse { message LPushResponse {
} }
message LpushxRequest { message LPushXRequest {
BaseKey key = 1; BaseKey key = 1;
repeated string values = 2; repeated string values = 2;
} }
message LpushxResponse { message LPushXResponse {
} }
message LrangeRequest { message LRangeRequest {
BaseKey key = 1; BaseKey key = 1;
int32 start = 2; int32 start = 2;
int32 end = 3; int32 end = 3;
} }
message LrangeResponse { message LRangeResponse {
repeated string values = 2; repeated string values = 2;
} }
message LremRequest { message LRemRequest {
BaseKey key = 1; BaseKey key = 1;
// count > 0 count < 0 // count > 0 count < 0
int32 count = 2; int32 count = 2;
string value = 3; string value = 3;
} }
message LremResponse { message LRemResponse {
int32 count = 1; int32 count = 1;
} }
message LsetRequest { message LSetRequest {
BaseKey key = 1; BaseKey key = 1;
int32 index = 2; int32 index = 2;
string value = 3; string value = 3;
} }
message LsetResponse { message LSetResponse {
} }
message RpopRequest { message RPopRequest {
BaseKey key = 1; BaseKey key = 1;
int32 count = 2; int32 count = 2;
} }
message RpopResponse { message RPopResponse {
repeated string result = 1; repeated string result = 1;
} }
message LtrimRequest { message LTrimRequest {
BaseKey key = 1; BaseKey key = 1;
int32 start = 2; int32 start = 2;
int32 end = 3; int32 end = 3;
} }
message LtrimResponse { message LTrimResponse {
} }
message RpushRequest { message RPushRequest {
BaseKey key = 1; BaseKey key = 1;
repeated string values = 2; repeated string values = 2;
} }
message RpushResponse { message RPushResponse {
} }
message RpushxRequest { message RPushXRequest {
BaseKey key = 1; BaseKey key = 1;
repeated string values = 2; repeated string values = 2;
} }
message RpushxResponse { message RPushXResponse {
} }

View File

@ -14,22 +14,22 @@ service CommServer {
rpc Get (GetRequest) returns (GetResponse); rpc Get (GetRequest) returns (GetResponse);
rpc Add (AddRequest) returns (AddResponse); rpc Add (AddRequest) returns (AddResponse);
rpc Reduce (ReduceRequest) returns (ReduceResponse); rpc Reduce (ReduceRequest) returns (ReduceResponse);
rpc Setbit (SetbitRequest) returns (SetbitResponse); rpc SetBit (SetBitRequest) returns (SetBitResponse);
rpc Getbit (GetbitRequest) returns (GetbitResponse); rpc GetBit (GetBitRequest) returns (GetBitResponse);
rpc Getrange (GetrangeRequest) returns (GetrangeResponse); rpc GetRange (GetRangeRequest) returns (GetRangeResponse);
rpc Getset (GetsetRequest) returns (GetsetResponse); rpc GetSet (GetSetRequest) returns (GetSetResponse);
rpc Strlen (StrlenRequest) returns (StrlenResponse); rpc StrLen (StrLenRequest) returns (StrLenResponse);
rpc Setnx (SetnxRequest) returns (SetnxResponse); rpc Setnx (SetnxRequest) returns (SetnxResponse);
rpc Lindex (LindexRequest) returns (LindexResponse); rpc LIndex (LIndexRequest) returns (LIndexResponse);
rpc Llen (LlenRequest) returns (LlenResponse); rpc LLen (LLenRequest) returns (LLenResponse);
rpc Lpop (LpopRequest) returns (LpopResponse); rpc LPop (LPopRequest) returns (LPopResponse);
rpc Lpush (LpushRequest) returns (LpushResponse); rpc LPush (LPushRequest) returns (LPushResponse);
rpc Lpushx (LpushxRequest) returns (LpushxResponse); rpc LPushX (LPushXRequest) returns (LPushXResponse);
rpc Lrange (LrangeRequest) returns (LrangeResponse); rpc LRange (LRangeRequest) returns (LRangeResponse);
rpc Lrem (LremRequest) returns (LremResponse); rpc LRem (LRemRequest) returns (LRemResponse);
rpc Lset (LsetRequest) returns (LsetResponse); rpc LSet (LSetRequest) returns (LSetResponse);
rpc Rpop (RpopRequest) returns (RpopResponse); rpc RPop (RPopRequest) returns (RPopResponse);
rpc Ltrim (LtrimRequest) returns (LtrimResponse); rpc LTrim (LTrimRequest) returns (LTrimResponse);
rpc Rpush (RpushRequest) returns (RpushResponse); rpc RPush (RPushRequest) returns (RPushResponse);
rpc Rpushx (RpushxRequest) returns (RpushxResponse); rpc RPushX (RPushXRequest) returns (RPushXResponse);
} }

View File

@ -37,50 +37,6 @@ message ReduceResponse {
string result = 2; string result = 2;
} }
message SetbitRequest {
BaseKey key = 1;
bool val = 2;
int32 offer = 3;
}
message SetbitResponse {
}
message GetbitRequest {
BaseKey key = 1;
int32 offer = 3;
}
message GetbitResponse {
bool val = 2;
}
message GetrangeRequest {
BaseKey key = 1;
int32 start = 2;
int32 end = 3;
}
message GetrangeResponse {
string result = 2;
}
message GetsetRequest {
BaseKey key = 1;
string val = 2;
}
message GetsetResponse {
string result = 2;
}
message StrlenRequest {
BaseKey key = 1;
}
message StrlenResponse {
int32 length = 1;
}
message SetnxRequest { message SetnxRequest {
BaseKey key = 1; BaseKey key = 1;
@ -89,3 +45,49 @@ message SetnxRequest {
message SetnxResponse { message SetnxResponse {
} }
message SetBitRequest {
BaseKey key = 1;
bool val = 2;
int32 offer = 3;
}
message SetBitResponse {
string result = 2;
}
message GetBitRequest {
BaseKey key = 1;
int32 offer = 2;
}
message GetBitResponse {
bool val = 1;
}
message GetRangeRequest {
BaseKey key = 1;
int32 start = 2;
int32 end = 3;
}
message GetRangeResponse {
string result = 1;
}
message GetSetRequest {
BaseKey key = 1;
string val = 2;
}
message GetSetResponse {
string result = 1;
}
message StrLenRequest {
BaseKey key = 1;
}
message StrLenResponse {
int32 length = 1;
}

View File

@ -3,7 +3,7 @@ import os
import yaml import yaml
sysPath = os.getcwd() sysPath = os.getcwd()
tempPath = f"{sysPath}/pkg/structure/generate" tempPath = f"{sysPath}/storage/temp"
structurePath = f"{sysPath}/pkg/structure" structurePath = f"{sysPath}/pkg/structure"
protobufPath = f"{sysPath}/protobuf" protobufPath = f"{sysPath}/protobuf"
@ -30,10 +30,8 @@ def load_conf():
# 生成对应的数据结构proto文件 # 生成对应的数据结构proto文件
def mk_structure(cfg_camel): def mk_structure(cfg_camel):
path = "protobuf"
storagePath = f"{protobufPath}/storage.proto"
for key, value in cfg_camel.items(): for key, value in cfg_camel.items():
proto_path = path + '/' + key + '.proto' proto_path = f"{protobufPath}/{key}.proto"
if not os.path.exists(proto_path): # 如果这个文件不存在 if not os.path.exists(proto_path): # 如果这个文件不存在
'''生成对应的数据结构proto文件''' '''生成对应的数据结构proto文件'''
file = open(proto_path, 'w') file = open(proto_path, 'w')
@ -81,6 +79,6 @@ def mk_storage(cfg_camel):
if __name__ == "__main__": if __name__ == "__main__":
conf, cfg_camel = load_conf() _, cfg_camel = load_conf()
mk_structure(cfg_camel) # 生成对应的数据结构proto文件 mk_structure(cfg_camel) # 生成对应的数据结构proto文件
mk_storage(cfg_camel) mk_storage(cfg_camel)

View File

@ -4,8 +4,7 @@ import yaml
from jinja2 import Template from jinja2 import Template
sysPath = os.getcwd() sysPath = os.getcwd()
tempPath = f"{sysPath}/pkg/structure/generate" tempPath = f"{sysPath}/storage/temp"
structurePath = f"{sysPath}/pkg/structure"
protobufPath = f"{sysPath}/protobuf" protobufPath = f"{sysPath}/protobuf"
storagePath = f"{sysPath}/storage" storagePath = f"{sysPath}/storage"
@ -14,7 +13,7 @@ class KeyMap(object):
def __init__(self, key: str, val) -> None: def __init__(self, key: str, val) -> None:
self.key = key self.key = key
self.val = val self.val = val
self.upper = [v.upper() for v in val] self.upper = val
def go_fmt(path: str): def go_fmt(path: str):
@ -27,7 +26,7 @@ def to_camel(val: str) -> str:
class KeyOption(object): class KeyOption(object):
def __init__(self, key, option): def __init__(self, key, option):
self.key = to_camel(key) self.key = key
self.option = option self.option = option
def __str__(self): def __str__(self):
@ -64,56 +63,23 @@ def set_structure_const_template(conf: dict):
key_map.append(KeyMap(key=k, val=v)) key_map.append(KeyMap(key=k, val=v))
for val in v: for val in v:
val_set.append(val.upper()) val_set.append(val)
template = Template(tem_text) template = Template(tem_text)
text = template.render(keys=keys, key_maps=key_map, sets=val_set) text = template.render(keys=keys, key_maps=key_map, sets=val_set)
temp_path = f"{structurePath}/const.gen.go" temp_path = f"{tempPath}/const.gen.go"
with open(temp_path, 'w', encoding='utf-8') as f:
f.write(text)
# 生成接口
def set_structure_interface(conf):
text = load_template("interface.template")
Dic = {}
template = Template(text)
for i in conf.keys():
x = i.lower().title()
Dic["".join(x.split("_"))] = conf[i]
yamlData = [Dic]
text = template.render(Data=yamlData)
temp_path = f"{structurePath}/interface.gen.go"
with open(temp_path, 'w', encoding='utf-8') as f:
f.write(text)
def set_storage_server(server_conf):
mod_name = [i.replace("_", "").lower() for i in server_conf.keys()]
option = []
for key, item in server_conf.items():
option.append(KeyOption(key, item))
text = load_template("storage.template")
template = Template(text)
text = template.render(option=option, mod_name=mod_name)
temp_path = f"{storagePath}/server/single.gen.go"
with open(temp_path, 'w', encoding='utf-8') as f: with open(temp_path, 'w', encoding='utf-8') as f:
f.write(text) f.write(text)
def format_code_go(): def format_code_go():
go_fmt(f"{structurePath}/interface.gen.go") go_fmt(f"{tempPath}/const.gen.go")
go_fmt(f"{structurePath}/const.gen.go")
go_fmt(f"{storagePath}/server/*.go")
if __name__ == "__main__": if __name__ == "__main__":
conf, cfg_camel = load_conf() conf, cfg_camel = load_conf()
set_structure_const_template(conf)
# set_structure_interface(cfg_camel) set_structure_const_template(cfg_camel)
# set_storage_server(cfg_camel)
# 格式化代码 # 格式化代码
format_code_go() format_code_go()

View File

@ -44,7 +44,7 @@ var rootCmd = &cobra.Command{
server.ElegantExitServer(s) server.ElegantExitServer(s)
logx.Info("start gateway in addr: %s", tcpAddr.String()) logx.Info("start storage in addr: %s", tcpAddr.String())
if err := s.Serve(listen); err != nil { if err := s.Serve(listen); err != nil {
logx.Errorln(err) logx.Errorln(err)
} }

View File

@ -8,10 +8,10 @@ import (
"gitee.com/timedb/wheatCache/pkg/proto" "gitee.com/timedb/wheatCache/pkg/proto"
) )
func (s *serverSingle) Lindex( func (s *serverSingle) LIndex(
ctx context.Context, ctx context.Context,
req *proto.LindexRequest, req *proto.LIndexRequest,
) (*proto.LindexResponse, error) { ) (*proto.LIndexResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LINdex(req.Key, req.Index) return s.dao.LINdex(req.Key, req.Index)
}) })
@ -25,15 +25,15 @@ func (s *serverSingle) Lindex(
return nil, err return nil, err
} }
return &proto.LindexResponse{ return &proto.LIndexResponse{
Result: resp.(string), Result: resp.(string),
}, nil }, nil
} }
func (s *serverSingle) Llen( func (s *serverSingle) LLen(
ctx context.Context, ctx context.Context,
req *proto.LlenRequest, req *proto.LLenRequest,
) (*proto.LlenResponse, error) { ) (*proto.LLenResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LLen(req.Key) return s.dao.LLen(req.Key)
}) })
@ -47,15 +47,15 @@ func (s *serverSingle) Llen(
return nil, err return nil, err
} }
return &proto.LlenResponse{ return &proto.LLenResponse{
Length: resp.(int32), Length: resp.(int32),
}, nil }, nil
} }
func (s *serverSingle) Lpop( func (s *serverSingle) LPop(
ctx context.Context, ctx context.Context,
request *proto.LpopRequest, request *proto.LPopRequest,
) (*proto.LpopResponse, error) { ) (*proto.LPopResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LPop(request.Key, request.Count) return s.dao.LPop(request.Key, request.Count)
}) })
@ -69,15 +69,15 @@ func (s *serverSingle) Lpop(
return nil, err return nil, err
} }
return &proto.LpopResponse{ return &proto.LPopResponse{
Results: resp.([]string), Results: resp.([]string),
}, nil }, nil
} }
func (s *serverSingle) Lpush( func (s *serverSingle) LPush(
ctx context.Context, ctx context.Context,
req *proto.LpushRequest, req *proto.LPushRequest,
) (*proto.LpushResponse, error) { ) (*proto.LPushResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return nil, s.dao.LPush(req.Key, req.Values...) return nil, s.dao.LPush(req.Key, req.Values...)
}) })
@ -91,13 +91,13 @@ func (s *serverSingle) Lpush(
return nil, err return nil, err
} }
return &proto.LpushResponse{}, nil return &proto.LPushResponse{}, nil
} }
func (s *serverSingle) Lpushx( func (s *serverSingle) LPushX(
ctx context.Context, ctx context.Context,
req *proto.LpushxRequest, req *proto.LPushXRequest,
) (*proto.LpushxResponse, error) { ) (*proto.LPushXResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return nil, s.dao.LPush(req.Key, req.Values...) return nil, s.dao.LPush(req.Key, req.Values...)
}) })
@ -111,13 +111,13 @@ func (s *serverSingle) Lpushx(
return nil, err return nil, err
} }
return &proto.LpushxResponse{}, nil return &proto.LPushXResponse{}, nil
} }
func (s *serverSingle) Lrange( func (s *serverSingle) LRange(
ctx context.Context, ctx context.Context,
req *proto.LrangeRequest, req *proto.LRangeRequest,
) (*proto.LrangeResponse, error) { ) (*proto.LRangeResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LRange(req.Key, req.Start, req.End) return s.dao.LRange(req.Key, req.Start, req.End)
}) })
@ -131,15 +131,15 @@ func (s *serverSingle) Lrange(
return nil, err return nil, err
} }
return &proto.LrangeResponse{ return &proto.LRangeResponse{
Values: resp.([]string), Values: resp.([]string),
}, nil }, nil
} }
func (s *serverSingle) Lrem( func (s *serverSingle) LRem(
ctx context.Context, ctx context.Context,
req *proto.LremRequest, req *proto.LRemRequest,
) (*proto.LremResponse, error) { ) (*proto.LRemResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.LRemove(req.Key, req.Count, req.Value) return s.dao.LRemove(req.Key, req.Count, req.Value)
}) })
@ -153,15 +153,15 @@ func (s *serverSingle) Lrem(
return nil, err return nil, err
} }
return &proto.LremResponse{ return &proto.LRemResponse{
Count: resp.(int32), Count: resp.(int32),
}, nil }, nil
} }
func (s *serverSingle) Lset( func (s *serverSingle) LSet(
ctx context.Context, ctx context.Context,
req *proto.LsetRequest, req *proto.LSetRequest,
) (*proto.LsetResponse, error) { ) (*proto.LSetResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return nil, s.dao.LSet(req.Key, req.Index, req.Value) return nil, s.dao.LSet(req.Key, req.Index, req.Value)
}) })
@ -175,13 +175,13 @@ func (s *serverSingle) Lset(
return nil, err return nil, err
} }
return &proto.LsetResponse{}, nil return &proto.LSetResponse{}, nil
} }
func (s *serverSingle) Rpop( func (s *serverSingle) RPop(
ctx context.Context, ctx context.Context,
req *proto.RpopRequest, req *proto.RPopRequest,
) (*proto.RpopResponse, error) { ) (*proto.RPopResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.RPop(req.Key, req.Count) return s.dao.RPop(req.Key, req.Count)
}) })
@ -195,15 +195,15 @@ func (s *serverSingle) Rpop(
return nil, err return nil, err
} }
return &proto.RpopResponse{ return &proto.RPopResponse{
Result: resp.([]string), Result: resp.([]string),
}, nil }, nil
} }
func (s *serverSingle) Ltrim( func (s *serverSingle) LTrim(
ctx context.Context, ctx context.Context,
req *proto.LtrimRequest, req *proto.LTrimRequest,
) (*proto.LtrimResponse, error) { ) (*proto.LTrimResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return nil, s.dao.LTrim(req.Key, req.Start, req.End) return nil, s.dao.LTrim(req.Key, req.Start, req.End)
}) })
@ -217,13 +217,13 @@ func (s *serverSingle) Ltrim(
return nil, err return nil, err
} }
return &proto.LtrimResponse{}, nil return &proto.LTrimResponse{}, nil
} }
func (s *serverSingle) Rpush( func (s *serverSingle) RPush(
ctx context.Context, ctx context.Context,
req *proto.RpushRequest, req *proto.RPushRequest,
) (*proto.RpushResponse, error) { ) (*proto.RPushResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return nil, s.dao.RPush(req.Key, req.Values...) return nil, s.dao.RPush(req.Key, req.Values...)
}) })
@ -237,13 +237,13 @@ func (s *serverSingle) Rpush(
return nil, err return nil, err
} }
return &proto.RpushResponse{}, nil return &proto.RPushResponse{}, nil
} }
func (s *serverSingle) Rpushx( func (s *serverSingle) RPushX(
ctx context.Context, ctx context.Context,
req *proto.RpushxRequest, req *proto.RPushXRequest,
) (*proto.RpushxResponse, error) { ) (*proto.RPushXResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return nil, s.dao.RPushX(req.Key, req.Values...) return nil, s.dao.RPushX(req.Key, req.Values...)
}) })
@ -257,5 +257,5 @@ func (s *serverSingle) Rpushx(
return nil, err return nil, err
} }
return &proto.RpushxResponse{}, nil return &proto.RPushXResponse{}, nil
} }

View File

@ -94,10 +94,10 @@ func (s *serverSingle) Reduce(
}, nil }, nil
} }
func (s *serverSingle) Setbit( func (s *serverSingle) SetBit(
cxt context.Context, cxt context.Context,
req *proto.SetbitRequest, req *proto.SetBitRequest,
) (*proto.SetbitResponse, error) { ) (*proto.SetBitResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return nil, s.dao.Setbit(req.Key, req.Val, req.Offer) return nil, s.dao.Setbit(req.Key, req.Val, req.Offer)
}) })
@ -110,13 +110,13 @@ func (s *serverSingle) Setbit(
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &proto.SetbitResponse{}, nil return &proto.SetBitResponse{}, nil
} }
func (s *serverSingle) Getbit( func (s *serverSingle) GetBit(
cxt context.Context, cxt context.Context,
req *proto.GetbitRequest, req *proto.GetBitRequest,
) (*proto.GetbitResponse, error) { ) (*proto.GetBitResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.GetBit(req.Key, req.Offer) return s.dao.GetBit(req.Key, req.Offer)
}) })
@ -129,15 +129,15 @@ func (s *serverSingle) Getbit(
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &proto.GetbitResponse{ return &proto.GetBitResponse{
Val: flag.(bool), Val: flag.(bool),
}, nil }, nil
} }
func (s *serverSingle) Getrange( func (s *serverSingle) GetRange(
ctx context.Context, ctx context.Context,
req *proto.GetrangeRequest, req *proto.GetRangeRequest,
) (*proto.GetrangeResponse, error) { ) (*proto.GetRangeResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.Getrange(req.Key, req.Start, req.End) return s.dao.Getrange(req.Key, req.Start, req.End)
}) })
@ -150,15 +150,15 @@ func (s *serverSingle) Getrange(
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &proto.GetrangeResponse{ return &proto.GetRangeResponse{
Result: flag.(string), Result: flag.(string),
}, nil }, nil
} }
func (s *serverSingle) Getset( func (s *serverSingle) GetSet(
ctx context.Context, ctx context.Context,
req *proto.GetsetRequest, req *proto.GetSetRequest,
) (*proto.GetsetResponse, error) { ) (*proto.GetSetResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.Getset(req.Key, req.Val) return s.dao.Getset(req.Key, req.Val)
}) })
@ -171,15 +171,15 @@ func (s *serverSingle) Getset(
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &proto.GetsetResponse{ return &proto.GetSetResponse{
Result: result.(string), Result: result.(string),
}, nil }, nil
} }
func (s *serverSingle) Strlen( func (s *serverSingle) StrLen(
ctx context.Context, ctx context.Context,
req *proto.StrlenRequest, req *proto.StrLenRequest,
) (*proto.StrlenResponse, error) { ) (*proto.StrLenResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) { work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.Strlen(req.Key) return s.dao.Strlen(req.Key)
}) })
@ -192,7 +192,7 @@ func (s *serverSingle) Strlen(
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &proto.StrlenResponse{ return &proto.StrLenResponse{
Length: flag.(int32), Length: flag.(int32),
}, nil }, nil
} }

89
storage/temp/const.gen.go Normal file
View File

@ -0,0 +1,89 @@
// Code generated by gen-struct. DO NOT EDIT.
// make gen-struct generated
package structure
const (
DEFAULT_KEY = iota
STRING_X
LIST_X
)
const (
DEFAULT_COMM = iota
Set
Get
Add
Reduce
SetBit
GetBit
GetRange
GetSet
StrLen
Setnx
LIndex
LLen
LPop
LPush
LPushX
LRange
LRem
LSet
RPop
LTrim
RPush
RPushX
)
var CommKeyString = map[string]int{
"Set": STRING_X,
"Get": STRING_X,
"Add": STRING_X,
"Reduce": STRING_X,
"SetBit": STRING_X,
"GetBit": STRING_X,
"GetRange": STRING_X,
"GetSet": STRING_X,
"StrLen": STRING_X,
"Setnx": STRING_X,
"LIndex": LIST_X,
"LLen": LIST_X,
"LPop": LIST_X,
"LPush": LIST_X,
"LPushX": LIST_X,
"LRange": LIST_X,
"LRem": LIST_X,
"LSet": LIST_X,
"RPop": LIST_X,
"LTrim": LIST_X,
"RPush": LIST_X,
"RPushX": LIST_X,
}
var CommKey = map[int]int{
Set: STRING_X,
Get: STRING_X,
Add: STRING_X,
Reduce: STRING_X,
SetBit: STRING_X,
GetBit: STRING_X,
GetRange: STRING_X,
GetSet: STRING_X,
StrLen: STRING_X,
Setnx: STRING_X,
LIndex: LIST_X,
LLen: LIST_X,
LPop: LIST_X,
LPush: LIST_X,
LPushX: LIST_X,
LRange: LIST_X,
LRem: LIST_X,
LSet: LIST_X,
RPop: LIST_X,
LTrim: LIST_X,
RPush: LIST_X,
RPushX: LIST_X,
}

View File

@ -18,7 +18,7 @@ const (
) )
var CommKeyString = map[string]int { var CommKeyString = map[string]int {
{%- for kmp in key_maps -%} {%- for kmp in key_maps %}
{% for comm in kmp.val -%} {% for comm in kmp.val -%}
"{{comm}}": {{kmp.key}}, "{{comm}}": {{kmp.key}},
{% endfor -%} {% endfor -%}
@ -26,7 +26,7 @@ var CommKeyString = map[string]int {
} }
var CommKey = map[int]int { var CommKey = map[int]int {
{%- for kmp in key_maps -%} {%- for kmp in key_maps %}
{% for comm in kmp.upper -%} {% for comm in kmp.upper -%}
{{comm}}: {{kmp.key}}, {{comm}}: {{kmp.key}},
{% endfor -%} {% endfor -%}

28
storage/temp/tem.yaml Normal file
View File

@ -0,0 +1,28 @@
# 这里定义 storage 所有可以使用的操作,使用命令验证方案
# 定义结构体名称以及方法使, 方法全部小写使用 _ 分割,结构体名称全部大写且结构体名称需要加上 _X, 如 LIST_X
STRING_X:
- set
- get
- add
- reduce
- set_bit
- get_bit
- get_range
- get_set
- str_len
- setnx
LIST_X:
- l_index
- l_len
- l_pop
- l_push
- l_push_x # 列表不存在则不插入
- l_range
- l_rem
- l_set
- r_pop
- l_trim # 对列表进行切片
- r_push
- r_push_x # 对已经存在的列表尾插