首先,你需要安装并引入 Jedis 库。Jedis 是 Java 语言操作 Redis 的客户端。
接下来,你可以使用 Jedis 的 set() 方法将 JSONObject 对象转换为字符串并存储到 Redis 中:
Jedis jedis =new Jedis("localhost");
JSONObject json = new JSONObject();
json.put("name", "John");
json.put("age", 30);
jedis.set("user", json.toString());