package qiwu.xfllmdemo.controller; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import java.util.HashMap; import java.util.Map; public class RedisTap { JedisPool pool = new JedisPool("localhost", 6379); Jedis jedis; RedisTap() { jedis = pool.getResource(); // jedis.close(); try { // Store & Retrieve a simple string jedis.set("foo", "bar"); System.out.println(jedis.get("foo")); // prints bar // Store & Retrieve a HashMap Map hash = new HashMap<>();; hash.put("name", "John"); hash.put("surname", "Smith"); hash.put("company", "Redis"); hash.put("age", "29"); jedis.hset("user-session:123", hash); System.out.println(jedis.hgetAll("user-session:123")); // Prints: {name=John, surname=Smith, company=Redis, age=29} } catch (Exception ignored) { } } }