RedisTemplate Common Collection Instructions - boundValueOps (10)

      The basic configuration has been introduced in the previous " RedisTemplate Common Collection Usage Instructions (1) ", and now we directly introduce the use of the boundValueOps() method:

       First define a BoundValueOperations

BoundValueOperations boundValueOperations = redisTemplate.boundValueOps("bvo");

 1.append(String value)

     add value at the end of the original value

boundValueOperations.append("a");
boundValueOperations.append("b");

2.get(long start, long end)

    Get the value of the specified interval position

//Get the value from the specified position to the specified position
System.out.println("Get the value from the specified position to the specified position:" + boundValueOperations.get(0,2));

3.get()

     Get all values ​​of a string

// get all values
System.out.println("Get all values:" + boundValueOperations.get());

 4.set(V value)

     reset the value of the binding key

// reset the value
boundValueOperations.set("f");
System.out.println("Reset value:" + boundValueOperations.get());

5.set(V value, long timeout, TimeUnit unit)

    reset value after specified time

// reset after the specified time
boundValueOperations.set("wwww",5,TimeUnit.SECONDS);
System.out.println("Reset after the specified time:" + boundValueOperations.get());

 6.set(V value, long offset)

    After truncating the specified length of the original value, add the new value at the back

//Add the new value after intercepting the specified length of the original value
boundValueOperations.set("nnnnnn",3);
System.out.println("Truncate the specified length of the original value and add the new value at the back:" + boundValueOperations.get());

 7.setIfAbsent(V value)

    Add if no value exists

//Add if no value exists
boundValueOperations.setIfAbsent("mmm");
System.out.println("Add if no value exists:" + boundValueOperations.get());

 8. getAndSet ( Vvalue  )

     Get the old value and reassign the new value

//Get the original value and overwrite it with the new value
Object object = boundValueOperations.getAndSet("yyy");
System.out.print("Get the original value" + object);
System.out.println(", overwrite with new value: " + boundValueOperations.get());

 9.size()

    Get the length of the bound value

System.out.println("Length of value value:" + boundValueOperations.size());

 10.increment(double delta)和increment(long delta)

  Self-incrementing key value, provided that the type of the bound value is double or long

// Self-increment can only be done when it is a number type
boundValueOperations.increment(1);
System.out.println("Auto-increment can only be done when it is a number type:" + boundValueOperations.get());

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326678770&siteId=291194637