RESP for Java
A simple client to write commands using the RESP (REdis Serialization Protocol) protocol.
In Redis setting a key name with value Luigi has the following syntax:
> SET name Luigi
And in RESP gets pushed on the wire as follows:
*3\r\n$3\r\nSET\r\n$4\r\nname\r\n$5\r\nLuigi
Which means:
- The input has 3 parts
- A string ($) of 3 characters SET
- A string ($) of 4 characters name
- And a string ($) of 5 characters Luigi
Simplicity.
In Java, all you have to do is add the following maven dependency:
<dependency>
<groupId>com.foogaro.util</groupId>
<artifactId>resp4j</artifactId>
<version>0.3.16</version>
</dependency>
And your code will look like the following:
String[] commands = new String[]{"SET", "name", "Luigi"};
try {
Redis.run(redis -> redis.call(commands), "localhost", 6379);
} catch (IOException | RedisError e) {
e.printStackTrace();
throw new RedisException(e);
}
And your commands will be transformed into RESP commands and pushed to the Redis server.
Done.
To know more about Redis commands, visit the following link: