Ai
1 Star 0 Fork 1

go-spring2/spring-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
case_list.go 19.18 KB
一键复制 编辑 原始数据 按行查看 历史
kzhu 提交于 2025-04-04 07:38 +08:00 . feat: update package name
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package redis
import (
"context"
"testing"
"gitee.com/go-spring2/spring-base/assert"
)
func (c *Cases) LIndex() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.LPush(ctx, "mylist", "World")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.LPush(ctx, "mylist", "Hello")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.LIndex(ctx, "mylist", 0)
assert.Nil(t, err)
assert.Equal(t, r3, "Hello")
r4, err := c.LIndex(ctx, "mylist", -1)
assert.Nil(t, err)
assert.Equal(t, r4, "World")
_, err = c.LIndex(ctx, "mylist", 3)
assert.True(t, IsErrNil(err))
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "LPUSH mylist World",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "LPUSH mylist Hello",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "LINDEX mylist 0",
"Response": "\"Hello\""
}, {
"Protocol": "REDIS",
"Request": "LINDEX mylist -1",
"Response": "\"World\""
}, {
"Protocol": "REDIS",
"Request": "LINDEX mylist 3",
"Response": "NULL"
}]
}`,
}
}
func (c *Cases) LInsert() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.RPush(ctx, "mylist", "Hello")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.RPush(ctx, "mylist", "World")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.LInsertBefore(ctx, "mylist", "World", "There")
assert.Nil(t, err)
assert.Equal(t, r3, int64(3))
r4, err := c.LRange(ctx, "mylist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r4, []string{"Hello", "There", "World"})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "RPUSH mylist Hello",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist World",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "LINSERT mylist BEFORE World There",
"Response": "\"3\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 -1",
"Response": "\"Hello\",\"There\",\"World\""
}]
}`,
}
}
func (c *Cases) LLen() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.LPush(ctx, "mylist", "World")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.LPush(ctx, "mylist", "Hello")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.LLen(ctx, "mylist")
assert.Nil(t, err)
assert.Equal(t, r3, int64(2))
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "LPUSH mylist World",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "LPUSH mylist Hello",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "LLEN mylist",
"Response": "\"2\""
}]
}`,
}
}
func (c *Cases) LMove() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.RPush(ctx, "mylist", "one")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.RPush(ctx, "mylist", "two")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.RPush(ctx, "mylist", "three")
assert.Nil(t, err)
assert.Equal(t, r3, int64(3))
r4, err := c.LMove(ctx, "mylist", "myotherlist", "RIGHT", "LEFT")
assert.Nil(t, err)
assert.Equal(t, r4, "three")
r5, err := c.LMove(ctx, "mylist", "myotherlist", "LEFT", "RIGHT")
assert.Nil(t, err)
assert.Equal(t, r5, "one")
r6, err := c.LRange(ctx, "mylist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r6, []string{"two"})
r7, err := c.LRange(ctx, "myotherlist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r7, []string{"three", "one"})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "RPUSH mylist one",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist two",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist three",
"Response": "\"3\""
}, {
"Protocol": "REDIS",
"Request": "LMOVE mylist myotherlist RIGHT LEFT",
"Response": "\"three\""
}, {
"Protocol": "REDIS",
"Request": "LMOVE mylist myotherlist LEFT RIGHT",
"Response": "\"one\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 -1",
"Response": "\"two\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE myotherlist 0 -1",
"Response": "\"three\",\"one\""
}]
}`,
}
}
func (c *Cases) LPop() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.RPush(ctx, "mylist", "one", "two", "three", "four", "five")
assert.Nil(t, err)
assert.Equal(t, r1, int64(5))
r2, err := c.LPop(ctx, "mylist")
assert.Nil(t, err)
assert.Equal(t, r2, "one")
r3, err := c.LPopN(ctx, "mylist", 2)
assert.Nil(t, err)
assert.Equal(t, r3, []string{"two", "three"})
r4, err := c.LRange(ctx, "mylist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r4, []string{"four", "five"})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "RPUSH mylist one two three four five",
"Response": "\"5\""
}, {
"Protocol": "REDIS",
"Request": "LPOP mylist",
"Response": "\"one\""
}, {
"Protocol": "REDIS",
"Request": "LPOP mylist 2",
"Response": "\"two\",\"three\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 -1",
"Response": "\"four\",\"five\""
}]
}`,
}
}
func (c *Cases) LPos() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.RPush(ctx, "mylist", 'a', 'b', 'c', 'd', 1, 2, 3, 4, 3, 3, 3)
assert.Nil(t, err)
assert.Equal(t, r1, int64(11))
r2, err := c.LPos(ctx, "mylist", 3)
assert.Nil(t, err)
assert.Equal(t, r2, int64(6))
r3, err := c.LPosN(ctx, "mylist", "3", 0, "RANK", 2)
assert.Nil(t, err)
assert.Equal(t, r3, []int64{8, 9, 10})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "RPUSH mylist 97 98 99 100 1 2 3 4 3 3 3",
"Response": "\"11\""
}, {
"Protocol": "REDIS",
"Request": "LPOS mylist 3",
"Response": "\"6\""
}, {
"Protocol": "REDIS",
"Request": "LPOS mylist 3 COUNT 0 RANK 2",
"Response": "\"8\",\"9\",\"10\""
}]
}`,
}
}
func (c *Cases) LPush() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.LPush(ctx, "mylist", "world")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.LPush(ctx, "mylist", "hello")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.LRange(ctx, "mylist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r3, []string{"hello", "world"})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "LPUSH mylist world",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "LPUSH mylist hello",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 -1",
"Response": "\"hello\",\"world\""
}]
}`,
}
}
func (c *Cases) LPushX() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.LPush(ctx, "mylist", "World")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.LPushX(ctx, "mylist", "Hello")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.LPushX(ctx, "myotherlist", "Hello")
assert.Nil(t, err)
assert.Equal(t, r3, int64(0))
r4, err := c.LRange(ctx, "mylist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r4, []string{"Hello", "World"})
r5, err := c.LRange(ctx, "myotherlist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r5, []string{})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "LPUSH mylist World",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "LPUSHX mylist Hello",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "LPUSHX myotherlist Hello",
"Response": "\"0\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 -1",
"Response": "\"Hello\",\"World\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE myotherlist 0 -1",
"Response": ""
}]
}`,
}
}
func (c *Cases) LRange() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.RPush(ctx, "mylist", "one")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.RPush(ctx, "mylist", "two")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.RPush(ctx, "mylist", "three")
assert.Nil(t, err)
assert.Equal(t, r3, int64(3))
r4, err := c.LRange(ctx, "mylist", 0, 0)
assert.Nil(t, err)
assert.Equal(t, r4, []string{"one"})
r5, err := c.LRange(ctx, "mylist", -3, 2)
assert.Nil(t, err)
assert.Equal(t, r5, []string{"one", "two", "three"})
r6, err := c.LRange(ctx, "mylist", -100, 100)
assert.Nil(t, err)
assert.Equal(t, r6, []string{"one", "two", "three"})
r7, err := c.LRange(ctx, "mylist", 5, 10)
assert.Nil(t, err)
assert.Equal(t, r7, []string{})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "RPUSH mylist one",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist two",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist three",
"Response": "\"3\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 0",
"Response": "\"one\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist -3 2",
"Response": "\"one\",\"two\",\"three\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist -100 100",
"Response": "\"one\",\"two\",\"three\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 5 10",
"Response": ""
}]
}`,
}
}
func (c *Cases) LRem() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.RPush(ctx, "mylist", "hello")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.RPush(ctx, "mylist", "hello")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.RPush(ctx, "mylist", "foo")
assert.Nil(t, err)
assert.Equal(t, r3, int64(3))
r4, err := c.RPush(ctx, "mylist", "hello")
assert.Nil(t, err)
assert.Equal(t, r4, int64(4))
r5, err := c.LRem(ctx, "mylist", -2, "hello")
assert.Nil(t, err)
assert.Equal(t, r5, int64(2))
r6, err := c.LRange(ctx, "mylist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r6, []string{"hello", "foo"})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "RPUSH mylist hello",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist hello",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist foo",
"Response": "\"3\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist hello",
"Response": "\"4\""
}, {
"Protocol": "REDIS",
"Request": "LREM mylist -2 hello",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 -1",
"Response": "\"hello\",\"foo\""
}]
}`,
}
}
func (c *Cases) LSet() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.RPush(ctx, "mylist", "one")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.RPush(ctx, "mylist", "two")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.RPush(ctx, "mylist", "three")
assert.Nil(t, err)
assert.Equal(t, r3, int64(3))
r4, err := c.LSet(ctx, "mylist", 0, "four")
assert.Nil(t, err)
assert.True(t, IsOK(r4))
r5, err := c.LSet(ctx, "mylist", -2, "five")
assert.Nil(t, err)
assert.True(t, IsOK(r5))
r6, err := c.LRange(ctx, "mylist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r6, []string{"four", "five", "three"})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "RPUSH mylist one",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist two",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist three",
"Response": "\"3\""
}, {
"Protocol": "REDIS",
"Request": "LSET mylist 0 four",
"Response": "\"OK\""
}, {
"Protocol": "REDIS",
"Request": "LSET mylist -2 five",
"Response": "\"OK\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 -1",
"Response": "\"four\",\"five\",\"three\""
}]
}`,
}
}
func (c *Cases) LTrim() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.RPush(ctx, "mylist", "one")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.RPush(ctx, "mylist", "two")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.RPush(ctx, "mylist", "three")
assert.Nil(t, err)
assert.Equal(t, r3, int64(3))
r4, err := c.LTrim(ctx, "mylist", 1, -1)
assert.Nil(t, err)
assert.True(t, IsOK(r4))
r5, err := c.LRange(ctx, "mylist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r5, []string{"two", "three"})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "RPUSH mylist one",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist two",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist three",
"Response": "\"3\""
}, {
"Protocol": "REDIS",
"Request": "LTRIM mylist 1 -1",
"Response": "\"OK\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 -1",
"Response": "\"two\",\"three\""
}]
}`,
}
}
func (c *Cases) RPop() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.RPush(ctx, "mylist", "one", "two", "three", "four", "five")
assert.Nil(t, err)
assert.Equal(t, r1, int64(5))
r2, err := c.RPop(ctx, "mylist")
assert.Nil(t, err)
assert.Equal(t, r2, "five")
r3, err := c.RPopN(ctx, "mylist", 2)
assert.Nil(t, err)
assert.Equal(t, r3, []string{"four", "three"})
r4, err := c.LRange(ctx, "mylist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r4, []string{"one", "two"})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "RPUSH mylist one two three four five",
"Response": "\"5\""
}, {
"Protocol": "REDIS",
"Request": "RPOP mylist",
"Response": "\"five\""
}, {
"Protocol": "REDIS",
"Request": "RPOP mylist 2",
"Response": "\"four\",\"three\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 -1",
"Response": "\"one\",\"two\""
}]
}`,
}
}
func (c *Cases) RPopLPush() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.RPush(ctx, "mylist", "one")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.RPush(ctx, "mylist", "two")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.RPush(ctx, "mylist", "three")
assert.Nil(t, err)
assert.Equal(t, r3, int64(3))
r4, err := c.RPopLPush(ctx, "mylist", "myotherlist")
assert.Nil(t, err)
assert.Equal(t, r4, "three")
r5, err := c.LRange(ctx, "mylist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r5, []string{"one", "two"})
r6, err := c.LRange(ctx, "myotherlist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r6, []string{"three"})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "RPUSH mylist one",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist two",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist three",
"Response": "\"3\""
}, {
"Protocol": "REDIS",
"Request": "RPOPLPUSH mylist myotherlist",
"Response": "\"three\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 -1",
"Response": "\"one\",\"two\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE myotherlist 0 -1",
"Response": "\"three\""
}]
}`,
}
}
func (c *Cases) RPush() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.RPush(ctx, "mylist", "hello")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.RPush(ctx, "mylist", "world")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.LRange(ctx, "mylist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r3, []string{"hello", "world"})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "RPUSH mylist hello",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "RPUSH mylist world",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 -1",
"Response": "\"hello\",\"world\""
}]
}`,
}
}
func (c *Cases) RPushX() *Case {
return &Case{
Func: func(t *testing.T, ctx context.Context, c *Client) {
r1, err := c.RPush(ctx, "mylist", "Hello")
assert.Nil(t, err)
assert.Equal(t, r1, int64(1))
r2, err := c.RPushX(ctx, "mylist", "World")
assert.Nil(t, err)
assert.Equal(t, r2, int64(2))
r3, err := c.RPushX(ctx, "myotherlist", "World")
assert.Nil(t, err)
assert.Equal(t, r3, int64(0))
r4, err := c.LRange(ctx, "mylist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r4, []string{"Hello", "World"})
r5, err := c.LRange(ctx, "myotherlist", 0, -1)
assert.Nil(t, err)
assert.Equal(t, r5, []string{})
},
Data: `
{
"Session": "df3b64266ebe4e63a464e135000a07cd",
"Actions": [{
"Protocol": "REDIS",
"Request": "RPUSH mylist Hello",
"Response": "\"1\""
}, {
"Protocol": "REDIS",
"Request": "RPUSHX mylist World",
"Response": "\"2\""
}, {
"Protocol": "REDIS",
"Request": "RPUSHX myotherlist World",
"Response": "\"0\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE mylist 0 -1",
"Response": "\"Hello\",\"World\""
}, {
"Protocol": "REDIS",
"Request": "LRANGE myotherlist 0 -1",
"Response": ""
}]
}`,
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/go-spring2/spring-core.git
git@gitee.com:go-spring2/spring-core.git
go-spring2
spring-core
spring-core
v1.1.3

搜索帮助