package com.redis;
import java.util.Map;
import redis.clients.jedis.Jedis;
public class RedisTest {
public static void main(String[] args) {
Jedis jedis = new Jedis("localhost");
jedis.hset("student.scofield", "English", "45");
jedis.hset("student.scofield", "Math", "89");
jedis.hset("student.scofield", "Computer", "100");
Map<String, String> value = jedis.hgetAll("student.scofield");
for (Map.Entry<String, String> entry : value.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
}
}package com.redis;
import java.util.Map;
import redis.clients.jedis.Jedis;
public class RedisTest {
public static void main(String[] args) {
Jedis jedis = new Jedis("localhost");
jedis.hset("student.scofield", "English", "45");
jedis.hset("student.scofield", "Math", "89");
jedis.hset("student.scofield", "Computer", "100");
Map<String, String> value = jedis.hgetAll("student.scofield");
for (Map.Entry<String, String> entry : value.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
}
}
本文演示了如何使用Java的Jedis客户端库操作Redis的Hash类型数据,包括设置和获取多个字段值,并展示了如何遍历和打印所有字段及其对应值。
241

被折叠的 条评论
为什么被折叠?



