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
原文地址:http://blog.51cto.com/13552725/2328253