**设置key的生存时间EXPIRE **
当超过设置时间就取不到值了。
127.0.0.1:6380> EXPIRE k1 10
(integer) 1
127.0.0.1:6380> get k1
"v1"
127.0.0.1:6380> get k1
"v1"
127.0.0.1:6380> get k1
(nil)
**获取Key的生存时间ttl **
127.0.0.1:6380> EXPIRE k2 500
(integer) 1
127.0.0.1:6380> ttl k2
(integer) 495
设置key持久
127.0.0.1:6380> PERSIST k2
(integer) 1
设置key到毫秒
127.0.0.1:6380> PEXPIRE k2 10000
(integer) 1
查询所有的产品并返回json串给客户端
/**
* 查询redis通过json发送到客户端 @Title: searchGoods @Description: TODO @param @return
* void @throws
*/
@Test
public void searchGoods() {
// 返回json显示的话 把MAP转json toJsonFromMap
String pattern = "goods:*";
Set<String> keys = jedis.keys(pattern);
for (String key : keys) {
Map<String, String> map = jedis.hgetAll(key);
Set<String> fileds = map.keySet();
for (String filed : fileds) {
System.out.println(filed + ":" + map.get(filed));
}
}
}