Implement LSET command for ledis server (#384)

This commit is contained in:
Lunny Xiao 2020-05-10 12:57:04 +08:00 committed by GitHub
parent b245fa4172
commit 72deb0e7c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 6 deletions

View File

@ -18,12 +18,12 @@ PACKAGES ?= $(shell GO111MODULE=on go list -mod=vendor ./... | grep -v /vendor/)
all: build all: build
build: build:
go build -mod=vendor -o bin/ledis-server -tags '$(GO_BUILD_TAGS)' cmd/ledis-server/* go build -mod=vendor -o bin/ledis-server -tags '$(GO_BUILD_TAGS)' cmd/ledis-server/*.go
go build -mod=vendor -o bin/ledis-cli -tags '$(GO_BUILD_TAGS)' cmd/ledis-cli/* go build -mod=vendor -o bin/ledis-cli -tags '$(GO_BUILD_TAGS)' cmd/ledis-cli/*.go
go build -mod=vendor -o bin/ledis-benchmark -tags '$(GO_BUILD_TAGS)' cmd/ledis-benchmark/* go build -mod=vendor -o bin/ledis-benchmark -tags '$(GO_BUILD_TAGS)' cmd/ledis-benchmark/*.go
go build -mod=vendor -o bin/ledis-dump -tags '$(GO_BUILD_TAGS)' cmd/ledis-dump/* go build -mod=vendor -o bin/ledis-dump -tags '$(GO_BUILD_TAGS)' cmd/ledis-dump/*.go
go build -mod=vendor -o bin/ledis-load -tags '$(GO_BUILD_TAGS)' cmd/ledis-load/* go build -mod=vendor -o bin/ledis-load -tags '$(GO_BUILD_TAGS)' cmd/ledis-load/*.go
go build -mod=vendor -o bin/ledis-repair -tags '$(GO_BUILD_TAGS)' cmd/ledis-repair/* go build -mod=vendor -o bin/ledis-repair -tags '$(GO_BUILD_TAGS)' cmd/ledis-repair/*.go
vet: vet:
go vet -mod=vendor -tags '$(GO_BUILD_TAGS)' ./... go vet -mod=vendor -tags '$(GO_BUILD_TAGS)' ./...

View File

@ -74,6 +74,7 @@ var helpCommands = [][]string{
{"LPOP", "key", "List"}, {"LPOP", "key", "List"},
{"LPUSH", "key value [value ...]", "List"}, {"LPUSH", "key value [value ...]", "List"},
{"LRANGE", "key start stop", "List"}, {"LRANGE", "key start stop", "List"},
{"LSET", "key index value", "List"},
{"LTTL", "key", "List"}, {"LTTL", "key", "List"},
{"MGET", "key [key ...]", "KV"}, {"MGET", "key [key ...]", "KV"},
{"MSET", "key value [key value ...]", "KV"}, {"MSET", "key value [key value ...]", "KV"},

View File

@ -134,6 +134,24 @@ func lrangeCommand(c *client) error {
return nil return nil
} }
func lsetCommand(c *client) error {
args := c.args
if len(args) != 3 {
return ErrCmdParams
}
index, err := ledis.StrInt64(args[1], nil)
if err != nil {
return ErrValue
}
if err := c.db.LSet(args[0], int32(index), args[2]); err != nil {
return err
}
c.resp.writeStatus(OK)
return nil
}
func lclearCommand(c *client) error { func lclearCommand(c *client) error {
args := c.args args := c.args
if len(args) != 1 { if len(args) != 1 {
@ -479,6 +497,7 @@ func init() {
register("llen", llenCommand) register("llen", llenCommand)
register("lpop", lpopCommand) register("lpop", lpopCommand)
register("lrange", lrangeCommand) register("lrange", lrangeCommand)
register("lset", lsetCommand)
register("lpush", lpushCommand) register("lpush", lpushCommand)
register("rpop", rpopCommand) register("rpop", rpopCommand)
register("rpush", rpushCommand) register("rpush", rpushCommand)