redis基本操作之hmset/hmget
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis基本操作之hmset/hmget相关的知识,希望对你有一定的参考价值。
import redis.clients.jedis.Jedis;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class RedisUtil {
private static Jedis redis=new Jedis("192.168.146.101",6379);
public static DeviceInfo getdeviceid(String deviceid){
Boolean have = redis.exists(deviceid);
if(have){
List<String> list = redis.hmget(deviceid, "appplatform", "brand", "deviceStyle", "osType");
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setDeviceId(deviceid);
deviceInfo.setAppPlatform(list.get(0));
deviceInfo.setBrand(list.get(1));
deviceInfo.setDeviceStyle(list.get(2));
deviceInfo.setOsType(list.get(3));
return deviceInfo;
}else{
return null;
}
}
public static void setdeviceid(String devid , String platform , String brand , String deviceStyle , String osType){
Map<String,String> map=new HashMap<String, String>();
map.put("appplatform",platform);
map.put("brand",brand);
map.put("deviceStyle",deviceStyle);
map.put("osType",osType);
redis.hmset(devid,map);
}
public static String getappversion(String deviceid,String appid,String newversion){
String version = redis.hget(deviceid, appid);
if(version!=null){
return version;
}else{
redis.hset(deviceid,appid,newversion);
return newversion;
}
}
}
--redis-cli -h localhost -p 6379
redis-server &
keys *
get key1
select 0
flushdb
flushall
quit
config set protected-mode no
hgetall user_0
以上是关于redis基本操作之hmset/hmget的主要内容,如果未能解决你的问题,请参考以下文章