diff --git a/content/operate/oss_and_stack/stack-with-enterprise/gears-v1/jvm/classes/readers/commandoverrider.md b/content/operate/oss_and_stack/stack-with-enterprise/gears-v1/jvm/classes/readers/commandoverrider.md index 65a36d0a1c..c7a196679e 100644 --- a/content/operate/oss_and_stack/stack-with-enterprise/gears-v1/jvm/classes/readers/commandoverrider.md +++ b/content/operate/oss_and_stack/stack-with-enterprise/gears-v1/jvm/classes/readers/commandoverrider.md @@ -51,26 +51,24 @@ CommandOverrider overrider = new CommandOverrider(); overrider.setCommand("HSET"); // Only override HSET for keys that start with "user:" overrider.setPrefix("user:"); - + // Create the data pipe builder GearsBuilder.CreateGearsBuilder(overrider).map(r-> { - // Extract the key from the command arguments - String keyName = new String((byte[]) r[1], StandardCharsets.UTF_8); - - // Add a last_modified timestamp to the user's profile - GearsBuilder.execute("HSET", keyName, "last_modified", Long.toString(System.currentTimeMillis())); - - // Get the original HSET arguments - ArrayList commandArray = new ArrayList(); - for (int i=1; i < r.length; i++) { - commandArray.add(new String((byte[]) r[i], StandardCharsets.UTF_8)); + // Get the operation arguments + ArrayList operationArguments = new ArrayList(); + for (int i = 1; i < r.length; i++) { + operationArguments.add(new String((byte[]) r[i], StandardCharsets.UTF_8)); } - - // Run the original HSET command - GearsBuilder.callNext(commandArray.toArray(new String[0])); - - return "OK"; -}).register(); + + // Add a last-modified field and a corresponding timestamp to the operation arguments + operationArguments.add("last-modified"); + operationArguments.add(Long.toString(System.currentTimeMillis())); + + // Run the enriched HSET operation + Object reply = GearsBuilder.callNext(operationArguments.toArray(new String[0])); + + return reply.toString(); +}).register(ExecutionMode.SYNC); ``` After you register the previous code with the `RG.JEXECUTE` command, try to update the user's data with `HSET` to test it: