0
0
Redisquery~20 mins

Redis with Java (Jedis, Lettuce) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Java Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this Jedis command sequence?
Given a Jedis connection, what will be the output of the following commands?
jedis.set("key1", "value1");
String val = jedis.get("key1");
System.out.println(val);
Redis
jedis.set("key1", "value1");
String val = jedis.get("key1");
System.out.println(val);
AThrows NullPointerException
Bnull
CThrows JedisConnectionException
Dvalue1
Attempts:
2 left
💡 Hint
Remember that set stores a string value and get retrieves it.
📝 Syntax
intermediate
2:00remaining
Which option correctly initializes a Lettuce Redis client?
Choose the correct Java code snippet to create a Lettuce Redis client connected to localhost on default port 6379.
ARedisClient client = RedisClient.connect("localhost");
BRedisClient client = new RedisClient("localhost", 6379);
CRedisClient client = RedisClient.create("redis://localhost:6379");
DRedisClient client = RedisClient.create("http://localhost:6379");
Attempts:
2 left
💡 Hint
Lettuce uses URI format starting with redis://
optimization
advanced
2:00remaining
How to optimize multiple Redis commands in Jedis?
You want to execute multiple Redis commands efficiently in Jedis. Which approach reduces network overhead the most?
AOpen and close a new Jedis connection for each command
BUse Jedis pipelining to batch commands before sending
CUse multiple threads each with its own Jedis instance
DSend commands one by one synchronously
Attempts:
2 left
💡 Hint
Batching commands reduces round-trip time.
🔧 Debug
advanced
2:00remaining
Why does this Lettuce code throw a NullPointerException?
Consider this Lettuce code snippet:
RedisClient client = RedisClient.create("redis://localhost:6379");
StatefulRedisConnection connection = null;
RedisCommands syncCommands = connection.sync();
syncCommands.set("key", "value");

What causes the NullPointerException?
Redis
RedisClient client = RedisClient.create("redis://localhost:6379");
StatefulRedisConnection<String, String> connection = null;
RedisCommands<String, String> syncCommands = connection.sync();
syncCommands.set("key", "value");
Aconnection is null, so calling sync() causes NullPointerException
BRedisClient.create returns null causing failure
Cset command is invalid syntax in Lettuce
DsyncCommands is null because set returns null
Attempts:
2 left
💡 Hint
Check which variable is null before method call.
🧠 Conceptual
expert
2:00remaining
What is the main difference between Jedis and Lettuce clients?
Which statement best describes the key difference between Jedis and Lettuce Redis clients in Java?
AJedis is synchronous and blocking; Lettuce supports asynchronous and reactive APIs
BJedis supports clustering; Lettuce does not support clustering
CLettuce is only for Redis 6+; Jedis supports all Redis versions
DJedis uses Netty; Lettuce uses raw sockets
Attempts:
2 left
💡 Hint
Think about how each client handles command execution style.