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) }
|