2 回答
TA贡献1816条经验 获得超4个赞
这是我之前写的代代码,可以参考一下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import 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); } } } |
添加回答
举报