Jedispooled time

14 views
Skip to first unread message

Oscar Besga

unread,
Nov 28, 2025, 4:18:38 AM (5 days ago) Nov 28
to Jedis
Hi

I'm migrating my project from JedisPool + Jedis to JedisPooled
In one part i use 

List<String> time = jedis.time();

But I can't find this method or other similar in JedisPool

List<String> time = jedisPooled.time();

Gives a compilation error.

Does anybody know how to solve this ?

Thanks

Oscar Besga

unread,
Nov 29, 2025, 4:23:38 PM (3 days ago) Nov 29
to Jedis
Gemini reports this

The JedisPooled class (part of the UnifiedJedis family introduced in Jedis 4 and continued in Jedis 5) provides a high-level, thread-safe abstraction over a connection pool. However, it does not directly expose the time() method, as this is considered a server-administration command rather than a data operation.

To call the TIME command using JedisPooled, you should use the eval() method to execute a small Lua script. This is the standard "escape hatch" for running commands that are not directly exposed by the wrapper.

Here is how you can do it:

//Java
import redis.clients.jedis.JedisPooled;
import java.util.List;
public class RedisTimeExample {
    public static void main(String[] args) {
      // Initialize JedisPooled
      try (JedisPooled jedis = new JedisPooled("localhost", 6379)) {
         // Call the TIME command using a Lua script
         // redis.call('TIME') returns a list containing [unix_time, microseconds]
         Object result = jedis.eval("return redis.call('TIME')");
         // Cast the result to a List<String> (or List<Object> depending on your specific needs)
         if (result instanceof List) { 
               List<String> timeInfo = (List<String>) result;
               String unixTime = timeInfo.get(0); 
               String microseconds = timeInfo.get(1);
               System.out.println("Unix Time: " + unixTime);
               System.out.println("Microseconds: " + microseconds); 
         }
       }
    }
 }

Why use eval?

  • Missing Method: The UnifiedJedis interface (which JedisPooled implements) unifies commands across standalone, cluster, and sharded modes. Since TIME returns a specific server's time, it is ambiguous in a cluster/sharded context (which node's time do you want?), so it is often omitted from the unified interface.

  • Thread Safety: The eval method is thread-safe and handles the connection pool management automatically, just like set or get.




Do you agree ?
Reply all
Reply to author
Forward
0 new messages