package sql;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import java.util.Set;
public class redis {
public static void main(String[] args) {
JedisPool pool = new JedisPool("localhost", 6379);
Jedis jedis = pool.getResource();
jedis.flushDB();
jedis.set("name", "zhangsan");
System.out.println(jedis.get("name"));
Set<String> keys = jedis.keys("*");
for (String s : keys) {
System.out.println(s);
}
jedis.close();
pool.close();
}
}
目的:为了储存更加复杂的数据结构
package sql;
import org.apache.commons.lang3.SerializationUtils;
import pojo.Video;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
public class redis {
public static void main(String[] args) {
JedisPool pool = new JedisPool("localhost", 6379);
Jedis jedis = pool.getResource();
jedis.flushDB();
Video v1 = new Video();
byte[] b = SerializationUtils.serialize(v1);
jedis.set("video:10".getBytes(), b);
byte[] b1 = jedis.get("video:10".getBytes());
Video v2 = SerializationUtils.deserialize(b1);
System.out.println(v2);
jedis.close();
pool.close();
}
}
?
?