1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| func TestInsertList(t *testing.T) { client, _ := ConnectSingle() ctx := context.Background() key := "insertList" for _, val := range []string{"php", "go"} { client.LPush(ctx, key, val) result, _ := client.LRange(ctx, key, 0, -1).Result() fmt.Printf("LPush 从头部插入【%v】: %v\n", val,result) } for _,val := range []string{"张三","李四"} { client.RPush(ctx, key, val) result, _ := client.LRange(ctx, key, 0, -1).Result() fmt.Printf("RPush 从尾部插入【%v】: %v\n", val,result) } result, _ := client.LRange(ctx, key, 0, -1).Result() fmt.Printf("当前列表所有值: %+v\n", result)
client.LInsertBefore(ctx,key,"php","php5.6") result, _ = client.LRange(ctx, key, 0, -1).Result() fmt.Printf("在php前插入%v,当前列表所有值: %v\n", "php5.6",result) client.LInsertAfter(ctx,key,"go","go1.0") result, _ = client.LRange(ctx, key, 0, -1).Result() fmt.Printf("在go后插入%v,当前列表所有值: %v\n", "go1.0",result) }
|