Skip to content

Commit

Permalink
Remove GetOption
Browse files Browse the repository at this point in the history
  • Loading branch information
cybergarage committed Aug 21, 2022
1 parent 67cdec4 commit 041eeba
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion doc/server_impl.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (server *Server) Set(ctx *redis.DBContext, key string, val string, opt redi
return redis.NewOKMessage(), nil
}
func (server *Server) Get(ctx *redis.DBContext, key string, opt redis.GetOption) (*redis.Message, error) {
func (server *Server) Get(ctx *redis.DBContext, key string) (*redis.Message, error) {
dbID := ctx.ID()
....
Expand Down
8 changes: 3 additions & 5 deletions examples/go-redis-server/server/server_string_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (server *Server) Set(ctx *redis.DBContext, key string, val string, opt redi
return redis.NewOKMessage(), nil
}

func (server *Server) Get(ctx *redis.DBContext, key string, opt redis.GetOption) (*redis.Message, error) {
func (server *Server) Get(ctx *redis.DBContext, key string) (*redis.Message, error) {
db, err := server.GetDatabase(ctx.ID())
if err != nil {
return nil, err
Expand All @@ -85,9 +85,8 @@ func (server *Server) Get(ctx *redis.DBContext, key string, opt redis.GetOption)

func (server *Server) MSet(ctx *redis.DBContext, dict map[string]string, opt redis.MSetOption) (*redis.Message, error) {
if opt.NX {
getOpt := redis.GetOption{}
for key := range dict {
res, err := server.Get(ctx, key, getOpt)
res, err := server.Get(ctx, key)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -121,11 +120,10 @@ func (server *Server) MSet(ctx *redis.DBContext, dict map[string]string, opt red
}

func (server *Server) MGet(ctx *redis.DBContext, keys []string) (*redis.Message, error) {
getOpt := redis.GetOption{}
arrayMsg := redis.NewArrayMessage()
array, _ := arrayMsg.Array()
for _, key := range keys {
msg, err := server.Get(ctx, key, getOpt)
msg, err := server.Get(ctx, key)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion redis/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type GenericCommandHandler interface {
// StringHandler represents a core command hander interface for string commands.
type StringCommandHandler interface {
Set(ctx *DBContext, key string, val string, opt SetOption) (*Message, error)
Get(ctx *DBContext, key string, opt GetOption) (*Message, error)
Get(ctx *DBContext, key string) (*Message, error)
MSet(ctx *DBContext, dict map[string]string, opt MSetOption) (*Message, error)
MGet(ctx *DBContext, keys []string) (*Message, error)
}
Expand Down
3 changes: 0 additions & 3 deletions redis/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ type SetOption struct {
GET bool
}

type GetOption struct {
}

type MSetOption struct {
NX bool
}
Expand Down
3 changes: 1 addition & 2 deletions redis/server_core_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,11 @@ func (server *Server) registerCoreExecutors() {
// String commands.

server.RegisterExexutor("GET", func(ctx *DBContext, cmd string, args Arguments) (*Message, error) {
opt := GetOption{}
key, err := nextKeyArgument(cmd, args)
if err != nil {
return nil, err
}
return server.userCommandHandler.Get(ctx, key, opt)
return server.userCommandHandler.Get(ctx, key)
})

server.RegisterExexutor("SET", func(ctx *DBContext, cmd string, args Arguments) (*Message, error) {
Expand Down
9 changes: 3 additions & 6 deletions redis/server_sugar_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func (server *Server) registerSugarExecutors() {
// common internal sugar functions

incdecExecutor := func(ctx *DBContext, cmd string, key string, val int) (*Message, error) {
getOpt := GetOption{}
getRet, err := server.userCommandHandler.Get(ctx, key, getOpt)
getRet, err := server.userCommandHandler.Get(ctx, key)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -50,8 +49,7 @@ func (server *Server) registerSugarExecutors() {
if err != nil {
return nil, err
}
getOpt := GetOption{}
getRet, err := server.userCommandHandler.Get(ctx, key, getOpt)
getRet, err := server.userCommandHandler.Get(ctx, key)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -112,8 +110,7 @@ func (server *Server) registerSugarExecutors() {
if err != nil {
return nil, err
}
getOpt := GetOption{}
getRet, err := server.userCommandHandler.Get(ctx, key, getOpt)
getRet, err := server.userCommandHandler.Get(ctx, key)
if err != nil {
return NewNilMessage(), nil
}
Expand Down

0 comments on commit 041eeba

Please sign in to comment.