Interface TransactionsBaseCommands

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<java.lang.String> watch​(GlideString[] keys)
      Marks the given keys to be watched for conditional execution of a transaction.
      java.util.concurrent.CompletableFuture<java.lang.String> watch​(java.lang.String[] keys)
      Marks the given keys to be watched for conditional execution of a transaction.
    • Method Detail

      • watch

        java.util.concurrent.CompletableFuture<java.lang.String> watch​(java.lang.String[] keys)
        Marks the given keys to be watched for conditional execution of a transaction. Transactions will only execute commands if the watched keys are not modified before execution of the transaction.
        Parameters:
        keys - The keys to watch.
        Returns:
        OK.
        See Also:
        valkey.io for details.
        Example:
        
         assert client.watch(new String[] {"sampleKey"}).get().equals("OK");
         transaction.set("sampleKey", "foobar");
         Object[] result = client.exec(transaction, false).get();
         assert result != null; // Executes successfully and keys are unwatched.
        
         assert client.watch(new String[] {"sampleKey"}).get().equals("OK");
         transaction.set("sampleKey", "foobar");
         assert client.set("sampleKey", "hello world").get().equals("OK");
         Object[] result = client.exec(transaction, true).get();
         assert result == null; // null is returned when the watched key is modified before transaction execution.
         
      • watch

        java.util.concurrent.CompletableFuture<java.lang.String> watch​(GlideString[] keys)
        Marks the given keys to be watched for conditional execution of a transaction. Transactions will only execute commands if the watched keys are not modified before execution of the transaction.
        Parameters:
        keys - The keys to watch.
        Returns:
        OK.
        See Also:
        valkey.io for details.
        Example:
        
         assert client.watch(new GlideString[] {gs("sampleKey")}).get().equals("OK");
         transaction.set(gs("sampleKey"), gs("foobar"));
         Object[] result = client.exec(transaction, false).get();
         assert result != null; // Executes successfully and keys are unwatched.
        
         assert client.watch(new GlideString[] {gs("sampleKey")}).get().equals("OK");
         transaction.set(gs("sampleKey"), gs("foobar"));
         assert client.set(gs("sampleKey"), gs("hello world")).get().equals("OK");
         Object[] result = client.exec(transaction, true).get();
         assert result == null; // null is returned when the watched key is modified before transaction execution.