03.友盟項目--原始日誌數據生成(改進版)---redis存儲 用戶設備的信息

代碼升級java

redis工具類linux

 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上啓動redisnginx

詳細步驟git

--------------------------------github

1.開啓windows端的nginx   ----執行程序鏈接本機 默認啓動的是80 端口,看看配置文件是否是監聽80端口redis

 

2.開啓linux端nginxwindows

openresty
3.開redis

 4.app

查看日誌

 

詳細代碼見github----------後期完善dom

相關文章
相關標籤/搜索