03.友盟项目--原始日志数据生成(改进版)---redis存储 用户设备的信息

代码升级

redis工具类

 1 package com.star.phone.util;
 2 
 3 
 4 import com.star.phone.domain.DeviceInfo;
 5 import redis.clients.jedis.Jedis;
 6 
 7 import java.util.HashMap;
 8 import java.util.List;
 9 import java.util.Map;
10 
11 /**
12  * Jedis工具类
13  */
14 public class RedisUtil {
15     private static Jedis redis = new Jedis("192.168.116.101" , 6379) ;
16 
17     /**
18      * 按照设备id,查询设备信息
19      */
20     public static DeviceInfo getDeviceInfo(String devid){
21         boolean have = redis.exists(devid) ;
22         if(have){
23             List<String> list = redis.hmget(devid, "appplatform", "brand", "deviceStyle", "osType");
24             DeviceInfo dev = new DeviceInfo();
25             dev.setDeviceId(devid);
26             dev.setAppPlatform(list.get(0));
27             dev.setBrand(list.get(1));
28             dev.setDeviceStyle(list.get(2));
29             dev.setOsType(list.get(3));
30             return dev;
31         }
32         return null ;
33     }
34 
35     /**
36      * 按照设备id,查询设备信息
37      */
38     public static void setDeviceInfo(String devid , String platform , String brand , String deviceStyle , String osType) {
39         Map<String,String> map = new HashMap<String, String>() ;
40         map.put("appplatform" , platform);//平台
41         map.put("brand" , brand);    //品牌
42         map.put("deviceStyle" , deviceStyle);//机型
43         map.put("osType" , osType);    //操作系统
44         redis.hmset(devid , map) ;//(手机ID 用户唯一标识, 上面的所有信息)
45     }
46 
47     /**
48      * get或setAndGet
49      */
50     public static String getAppVersion(String devid , String appid , String newVersion) {
51         String appversion = redis.hget(devid,appid) ;
52         if(appversion != null){
53             return appversion ;
54         }
55         else{
56             redis.hset(devid,appid , newVersion) ;
57             return newVersion ;
58         }
59     }
60 
61 
62 
63 
64 }
redis工具类

生成数据时记得先在s101上启动redis

详细步骤

--------------------------------

1.开启windows端的nginx   ----执行程序连接本机 默认启动的是80 端口,看看配置文件是不是监听80端口

 

2.开启linux端nginx

openresty
3.开redis

 4.

查看日志

 

详细代码见github----------后期完善

posted @ 2018-10-30 15:50  star521  阅读(196)  评论(0编辑  收藏  举报