redis序列化数据查询

import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.ObjectInputStream; import redis.clients.jedis.Jedis; public class RedisDeserializeDemo { public static void main(String[] args) { // Redis 服务器地址和端口号 String redisHost = "localhost"; int redisPort = 16379; // Redis 认证密码 String redisPassword = "xxxxxxxxx"; // 替换为你的实际密码 // 创建Redis连接 Jedis jedis = new Jedis(redisHost, redisPort); // 认证 Redis 连接 jedis.auth(redisPassword); // 从Redis中获取序列化值 byte[] serializedValue = jedis.get("Basic_ConfiGuration_List_".getBytes()); // 反序列化Java对象 Object deserializedObject = deserialize(serializedValue); // 输出反序列化后的Java对象信息 System.out.println(deserializedObject.toString()); // 关闭Redis连接 jedis.close(); } public static Object deserialize(byte[] serializedObject) { Object deserializedObject = null; try { ByteArrayInputStream byteIn = new ByteArrayInputStream(serializedObject); ObjectInputStream in = new ObjectInputStream(byteIn); deserializedObject = in.readObject(); in.close(); byteIn.close(); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } return deserializedObject; } }
上一篇:网络技术-访问控制列表(ACL)


下一篇:化工防爆巡检机器人:在挑战中成长,为化工安全保驾护航