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

View File

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

View File

@ -37,50 +37,6 @@ message ReduceResponse {
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 {
BaseKey key = 1;
@ -89,3 +45,49 @@ message SetnxRequest {
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
sysPath = os.getcwd()
tempPath = f"{sysPath}/pkg/structure/generate"
tempPath = f"{sysPath}/storage/temp"
structurePath = f"{sysPath}/pkg/structure"
protobufPath = f"{sysPath}/protobuf"
@ -30,10 +30,8 @@ def load_conf():
# 生成对应的数据结构proto文件
def mk_structure(cfg_camel):
path = "protobuf"
storagePath = f"{protobufPath}/storage.proto"
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): # 如果这个文件不存在
'''生成对应的数据结构proto文件'''
file = open(proto_path, 'w')
@ -81,6 +79,6 @@ def mk_storage(cfg_camel):
if __name__ == "__main__":
conf, cfg_camel = load_conf()
_, cfg_camel = load_conf()
mk_structure(cfg_camel) # 生成对应的数据结构proto文件
mk_storage(cfg_camel)

View File

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

View File

@ -44,7 +44,7 @@ var rootCmd = &cobra.Command{
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 {
logx.Errorln(err)
}

View File

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

View File

@ -94,10 +94,10 @@ func (s *serverSingle) Reduce(
}, nil
}
func (s *serverSingle) Setbit(
func (s *serverSingle) SetBit(
cxt context.Context,
req *proto.SetbitRequest,
) (*proto.SetbitResponse, error) {
req *proto.SetBitRequest,
) (*proto.SetBitResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) {
return nil, s.dao.Setbit(req.Key, req.Val, req.Offer)
})
@ -110,13 +110,13 @@ func (s *serverSingle) Setbit(
if err != nil {
return nil, err
}
return &proto.SetbitResponse{}, nil
return &proto.SetBitResponse{}, nil
}
func (s *serverSingle) Getbit(
func (s *serverSingle) GetBit(
cxt context.Context,
req *proto.GetbitRequest,
) (*proto.GetbitResponse, error) {
req *proto.GetBitRequest,
) (*proto.GetBitResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.GetBit(req.Key, req.Offer)
})
@ -129,15 +129,15 @@ func (s *serverSingle) Getbit(
if err != nil {
return nil, err
}
return &proto.GetbitResponse{
return &proto.GetBitResponse{
Val: flag.(bool),
}, nil
}
func (s *serverSingle) Getrange(
func (s *serverSingle) GetRange(
ctx context.Context,
req *proto.GetrangeRequest,
) (*proto.GetrangeResponse, error) {
req *proto.GetRangeRequest,
) (*proto.GetRangeResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.Getrange(req.Key, req.Start, req.End)
})
@ -150,15 +150,15 @@ func (s *serverSingle) Getrange(
if err != nil {
return nil, err
}
return &proto.GetrangeResponse{
return &proto.GetRangeResponse{
Result: flag.(string),
}, nil
}
func (s *serverSingle) Getset(
func (s *serverSingle) GetSet(
ctx context.Context,
req *proto.GetsetRequest,
) (*proto.GetsetResponse, error) {
req *proto.GetSetRequest,
) (*proto.GetSetResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.Getset(req.Key, req.Val)
})
@ -171,15 +171,15 @@ func (s *serverSingle) Getset(
if err != nil {
return nil, err
}
return &proto.GetsetResponse{
return &proto.GetSetResponse{
Result: result.(string),
}, nil
}
func (s *serverSingle) Strlen(
func (s *serverSingle) StrLen(
ctx context.Context,
req *proto.StrlenRequest,
) (*proto.StrlenResponse, error) {
req *proto.StrLenRequest,
) (*proto.StrLenResponse, error) {
work := event.EventWorkFunc(func() (interface{}, error) {
return s.dao.Strlen(req.Key)
})
@ -192,7 +192,7 @@ func (s *serverSingle) Strlen(
if err != nil {
return nil, err
}
return &proto.StrlenResponse{
return &proto.StrLenResponse{
Length: flag.(int32),
}, 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 {
{%- for kmp in key_maps -%}
{%- for kmp in key_maps %}
{% for comm in kmp.val -%}
"{{comm}}": {{kmp.key}},
{% endfor -%}
@ -26,7 +26,7 @@ var CommKeyString = map[string]int {
}
var CommKey = map[int]int {
{%- for kmp in key_maps -%}
{%- for kmp in key_maps %}
{% for comm in kmp.upper -%}
{{comm}}: {{kmp.key}},
{% 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 # 对已经存在的列表尾插