Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement redis command 'BITOP' and 'BITFIELD'. #69

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion command/command.go
Expand Up @@ -6,11 +6,11 @@ import (
"strings"
"time"

"github.com/shafreeck/retry"
"github.com/meitu/titan/context"
"github.com/meitu/titan/db"
"github.com/meitu/titan/encoding/resp"
"github.com/meitu/titan/metrics"
"github.com/shafreeck/retry"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -58,6 +58,12 @@ func Integer(w io.Writer, v int64) OnCommit {
}
}

func Array(w io.Writer, v []resp.Value) OnCommit {
return func() {
resp.ReplyArray2(w, v)
}
}

// BytesArray replies a [][]byte when commit
func BytesArray(w io.Writer, a [][]byte) OnCommit {
return func() {
Expand Down
8 changes: 8 additions & 0 deletions command/error.go
Expand Up @@ -93,6 +93,14 @@ var (

//ErrDiscard without multi
ErrDiscard = errors.New("ERR DISCARD without MULTI")

ErrInvalidBitfieldType = errors.New("ERR Invalid bitfield type. Use something like i16 u8. Note that u64 is not supported but i64 is.")

ErrInvalidBitfieldOffset = errors.New("ERR bit offset is not an integer or out of range")

ErrInvalidBitfieldValue = errors.New("ERR value is not an integer or out of range")

ErrInvalidBitfieldOverflowType = errors.New("ERR Invalid OVERFLOW type specified")
)

//ErrUnKnownCommand return RedisError of the cmd
Expand Down
4 changes: 2 additions & 2 deletions command/init.go
Expand Up @@ -135,8 +135,8 @@ func init() {
"decrby": Desc{Proc: AutoCommit(DecrBy), Cons: Constraint{3, flags("wmF"), 1, 1, 1}},
"incrbyfloat": Desc{Proc: AutoCommit(IncrByFloat), Cons: Constraint{3, flags("wmF"), 1, 1, 1}},
"setbit": Desc{Proc: AutoCommit(SetBit), Cons: Constraint{4, flags("wm"), 1, 1, 1}},
// "bitop": Desc{Proc: AutoCommit(BitOp), Cons: Constraint{-4, flags("wm"), 2, -1, 1}},
// "bitfield": Desc{Proc: AutoCommit(BitField), Cons: Constraint{-2, flags("wm"), 1, 1, 1}},
"bitop": Desc{Proc: AutoCommit(BitOp), Cons: Constraint{-4, flags("wm"), 2, -1, 1}},
"bitfield": Desc{Proc: AutoCommit(BitField), Cons: Constraint{-4, flags("wm"), 2, -1, 1}},
"getbit": Desc{Proc: AutoCommit(GetBit), Cons: Constraint{3, flags("r"), 1, 1, 1}},
"bitcount": Desc{Proc: AutoCommit(BitCount), Cons: Constraint{-2, flags("r"), 1, 1, 1}},
"bitpos": Desc{Proc: AutoCommit(BitPos), Cons: Constraint{-3, flags("r"), 1, 1, 1}},
Expand Down