小怪兽爱吃肉
这是我之前写的代代码,可以参考一下:1234567891011121314151617181920212223242526272829303132333435363738394041import java.util.Set; import com.google.gson.Gson; import redis.clients.jedis.Jedis;import redis.clients.jedis.JedisPool;import redis.clients.jedis.JedisPoolConfig; public class App { public static void main(String[] args) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(5); config.setMaxWaitMillis(10000); config.setTestOnBorrow(false); JedisPool jedisPool = new JedisPool(config, "127.0.0.1", 6379); Jedis jedis = jedisPool.getResource(); jedis.flushDB(); jedis.set("name", "Tom"); User user = new User(1, "Tom", "User"); Gson gson = new Gson(); String json = gson.toJson(user); jedis.set("user1", json); Set<String> keys = jedis.keys("*"); for (String key : keys) { System.out.println(key); } }}