The basic configuration has been introduced in the previous " RedisTemplate Common Collection Usage Instructions (1) ", now we directly introduce the use of the boundListOps() method:
First define a BoundListOperations
//Define the binding key BoundListOperations boundListOperations = redisTemplate.boundListOps("lk");
1.leftPush(V value)和rightPush(V value)
Add value to bind key
//Add the value to the bound key boundListOperations.leftPush("h"); boundListOperations.leftPush("i"); boundListOperations.rightPush("a"); boundListOperations.rightPush("b");
2.range(long start, long end)
Get the interval value given in the bound key
//Get the value in the bound key boundListOperations.range(0,-1).forEach(v -> System.out.println("Get the value in the bound key" + v));
3.index(long index)
Get the value at a given location
//Get the value of a specific location System.out.println("Get the value of a specific position: " + boundListOperations.index(0));
4.leftPop()
Pop the value on the left
// pop the left value System.out.println("Pop left value:" + boundListOperations.leftPop());
5.rightPop()
Pop the value on the right
// pop the value on the right System.out.println("Pop right value:" + boundListOperations.rightPop());
Adds values to the left of the occurrence of the first value specified
//Add the value to the left of the first value specified boundListOperations.leftPush("i","w"); boundListOperations.range(0,-1).forEach(v -> System.out.println("Add value to the left of the first value specified: " + v));
Adds values to the right of the occurrence of the first value specified
//Add the value to the right of the first value specified boundListOperations.rightPush("i","x"); boundListOperations.range(0,-1).forEach(v -> System.out.println("Add value to the left of the first value specified: " + v));
8.leftPop(long timeout, TimeUnit unit)
Pop the value on the left after the specified time
// pop up the left value after the specified time boundListOperations.leftPop(1, TimeUnit.SECONDS);
9.rightPop(long timeout, TimeUnit unit)
Pops the value on the right after the specified time
// pop up the value on the right after the specified time boundListOperations.rightPop(1, TimeUnit.SECONDS);
10.leftPushAll(V... values)
Bulk add values on the left
// add values in batches on the left boundListOperations.leftPushAll("y","g"); boundListOperations.range(0,-1).forEach(v -> System.out.println("Add values in batches on the left: " + v));
11.rightPushAll(V... values)
Bulk add values on the right
//add values in batches on the right boundListOperations.rightPushAll("b","r"); boundListOperations.range(0,-1).forEach(v -> System.out.println("Add values in batches on the right: " + v));
12.leftPushIfPresent(V value)
Add non-existing value to the left
//Add non-existing value to the left boundListOperations.leftPushIfPresent("k"); boundListOperations.leftPushIfPresent(";"); boundListOperations.range(0,-1).forEach(v -> System.out.println("Add non-existent value to the left: " + v));
13.rightPushIfPresent(V value)
Add non-existing value to the right
//Add non-existing value to the right boundListOperations.rightPushIfPresent("k"); boundListOperations.rightPushIfPresent(";"); System.out.println("Add non-existent value to the right: " + boundListOperations.range(0,-1).toString());
14.remove(long count, Object value)
remove the specified number of values
// remove the number of specified values long removeCount = boundListOperations.remove(2,"i"); System.out.println("Remove the number of specified values:" + removeCount); System.out.println("Remaining value after removing the specified number of values: " + boundListOperations.range(0,-1).toString());
add value at specified location
// set the value at the specified location boundListOperations.set(0,"j"); System.out.println("Set the value at the specified position: " + boundListOperations.range(0,-1).toString());
16.trim(long start, long end)
Truncate the value of the original interval to the new value
//Intercept the value of the specified interval position boundListOperations.trim(1,3); System.out.println("Intercept the value of the specified range position: " + boundListOperations.range(0,-1).toString());