Senior
What experience do you have with Redis? What data structures and commands have you used?
sobes.tech AI
Answer from AI
In working with Redis, I used various data structures and commands to optimize performance and simplify application logic.
Main structures and commands:
- Strings: SET, GET, INCR, DECR — for storing simple values and counters.
- Hashes: HSET, HGET, HGETALL — for storing objects with fields.
- Lists: LPUSH, RPUSH, LPOP, RPOP — for implementing queues and stacks.
- Sets: SADD, SREM, SMEMBERS — for storing unique elements.
- Sorted Sets: ZADD, ZRANGE — for rankings and sorted data.
Example of using a hash to store user information:
Jedis jedis = new Jedis("localhost");
// Adding user data
jedis.hset("user:1000", "name", "Ivan");
jedis.hset("user:1000", "age", "30");
// Retrieving all fields
Map<String, String> user = jedis.hgetAll("user:1000");
System.out.println(user);
I also used transactions and Lua scripts for atomic operations and data consistency.