mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-06 01:07:06 +08:00
support count of LPop and RPop
This commit is contained in:
@@ -287,6 +287,21 @@ func TestLPop(t *testing.T) {
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Errorf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes()))
|
||||
}
|
||||
|
||||
// test count
|
||||
testDB.Exec(nil, utils.ToCmdLine2("rpush", values...))
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("lpop", key, strconv.Itoa(10)))
|
||||
reply, ok := result.(*protocol.MultiBulkReply)
|
||||
if !ok {
|
||||
t.Errorf("parse error expected *protocol.MultiBulkReply, actually %s", result)
|
||||
}
|
||||
for i, arg := range reply.Args {
|
||||
result := string(arg)
|
||||
expected := values[i+1]
|
||||
if result != expected {
|
||||
t.Errorf("expected %s, actually %s", expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRPop(t *testing.T) {
|
||||
@@ -308,6 +323,21 @@ func TestRPop(t *testing.T) {
|
||||
if !utils.BytesEquals(result.ToBytes(), expected.ToBytes()) {
|
||||
t.Errorf("expected %s, actually %s", string(expected.ToBytes()), string(result.ToBytes()))
|
||||
}
|
||||
|
||||
// test count
|
||||
testDB.Exec(nil, utils.ToCmdLine2("rpush", values...))
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("rpop", key, strconv.Itoa(10)))
|
||||
reply, ok := result.(*protocol.MultiBulkReply)
|
||||
if !ok {
|
||||
t.Errorf("parse error expected *protocol.MultiBulkReply, actually %s", result)
|
||||
}
|
||||
for i, arg := range reply.Args {
|
||||
result := string(arg)
|
||||
expected := values[len(values)-i-1]
|
||||
if result != expected {
|
||||
t.Errorf("expected %s, actually %s", expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRPopLPush(t *testing.T) {
|
||||
@@ -476,6 +506,14 @@ func TestUndoLPop(t *testing.T) {
|
||||
}
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("llen", key))
|
||||
asserts.AssertIntReply(t, result, 2)
|
||||
cmdLine = utils.ToCmdLine("lpop", key, strconv.Itoa(2))
|
||||
undoCmdLines = undoRPop(testDB, cmdLine[1:])
|
||||
testDB.Exec(nil, cmdLine)
|
||||
for _, cmdLine := range undoCmdLines {
|
||||
testDB.Exec(nil, cmdLine)
|
||||
}
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("llen", key))
|
||||
asserts.AssertIntReply(t, result, 2)
|
||||
}
|
||||
|
||||
func TestUndoLSet(t *testing.T) {
|
||||
@@ -507,6 +545,14 @@ func TestUndoRPop(t *testing.T) {
|
||||
}
|
||||
result := testDB.Exec(nil, utils.ToCmdLine("llen", key))
|
||||
asserts.AssertIntReply(t, result, 2)
|
||||
cmdLine = utils.ToCmdLine("rpop", key, strconv.Itoa(2))
|
||||
undoCmdLines = undoRPop(testDB, cmdLine[1:])
|
||||
testDB.Exec(nil, cmdLine)
|
||||
for _, cmdLine := range undoCmdLines {
|
||||
testDB.Exec(nil, cmdLine)
|
||||
}
|
||||
result = testDB.Exec(nil, utils.ToCmdLine("llen", key))
|
||||
asserts.AssertIntReply(t, result, 2)
|
||||
}
|
||||
|
||||
func TestUndoRPopLPush(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user