Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new Jedis client connection.
Redis
Jedis jedis = new Jedis([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect IP address or hostname that does not point to the Redis server.
✗ Incorrect
The Jedis client connects to Redis using the server address. "127.0.0.1" is the standard localhost IP.
2fill in blank
mediumComplete the code to set a key "user" with value "Alice" in Redis using Jedis.
Redis
jedis.[1]("user", "Alice");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
get which retrieves data instead of setting it.✗ Incorrect
The set method stores a value for a given key in Redis.
3fill in blank
hardFix the error in the Lettuce code to connect to Redis synchronously.
Redis
RedisClient client = RedisClient.create("redis://localhost:6379"); StatefulRedisConnection<String, String> connection = client.[1]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
connectAsync() which returns a future, not a direct connection.✗ Incorrect
The connect() method opens a synchronous connection to Redis in Lettuce.
4fill in blank
hardFill both blanks to set and then get a key "count" using Jedis.
Redis
jedis.[1]("count", "10"); String value = jedis.[2]("count");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to get a value before setting it.
Using
del or exists instead of get.✗ Incorrect
First, set stores the value, then get retrieves it.
5fill in blank
hardFill all three blanks to create a Lettuce client, connect, and set a key "name" to "Bob".
Redis
RedisClient client = RedisClient.[1]("redis://localhost:6379"); StatefulRedisConnection<String, String> connection = client.[2](); RedisCommands<String, String> commands = connection.[3](); commands.set("name", "Bob");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
open instead of sync for commands.Confusing
connectAsync with connect.✗ Incorrect
Use create to make the client, connect to open connection, and sync to get synchronous commands.