redis How to Connect to Redis in Java using Jedis Executing Commands


To execute a Redis command using Jedis, you make method calls against the Jedis object you created from the pool. Jedis exposes Redis commands as method calls, some example are:

- String get(String key) 
- Long geoadd(String key, double longitude, double latitude, String member)
- List<String> hmget(String key, String... fields)
- Long hsetnx(String key, String field, String value)

If you wanted to set the value of a String key in Redis you would use a code block similar to:

try (Jedis jedis = pool.getResource()) {

   String myKey = "users:20";
   String myValue = "active";

   jedis.set(myKey, myValue);