RedisCacheTool参考其中的文件读写功能
- package com.jr.market.tool;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import org.apache.activemq.console.Main;
- import org.apache.commons.io.FileUtils;
- import org.apache.commons.io.FilenameUtils;
- import redis.clients.jedis.JedisPoolConfig;
- import redis.clients.jedis.JedisShardInfo;
- import redis.clients.jedis.ShardedJedisPool;
- import ch.qos.logback.core.util.FileUtil;
- import com.xiaomi.jr.market.constants.RpInvConstants;
- import com.xiaomi.jr.market.domain.RpReciveInput;
- import com.xiaomi.jr.market.gift.dto.FpSettleDetail;
- import com.xiaomi.jr.market.util.CacheKey;
- import com.xiaomi.jr.market.util.DateUtil;
- import com.xiaomi.jr.market.util.JsonExceptionUtil;
- import com.xiaomi.jr.market.util.QueuesCfg;
- import com.xiaomi.operation.platform.hogwarts.util.StringUtil;
- import com.xiaomi.operation.platform.tsg.base.core.utils.JsonUtil;
- import com.xiaomi.operation.platform.tsg.base.core.utils.ResponseVo;
- public class RedisCacheTool {
- /**
- * @param args
- * @throws IOException
- *
- *
- * xxxxxx 19000
- * xxxxxx 19102
- */
- public static boolean connect = false ;
- public static RedisClientImpl cl = null ;
- public static void connect(String[] infos) {
- if(!connect) {
- String host = infos[1] ;
- String port = infos[2] ;
- int ports = -1;
- try{
- ports = Integer.parseInt(infos[2]);
- } catch (Exception e) {
- e.printStackTrace() ;
- return ;
- }
- JedisPoolConfig config = new JedisPoolConfig();
- JedisShardInfo info = new JedisShardInfo(host,ports) ;
- List<JedisShardInfo> jedisInfo = new ArrayList<JedisShardInfo>() ;
- jedisInfo.add(info) ;
- ShardedJedisPool pool = new ShardedJedisPool(config,jedisInfo) ;
- cl = new RedisClientImpl() ;
- cl.setJedisPool(pool) ;
- System.out.println("连接成功 [" + host +":" +ports+"]" ) ;
- connect = true ;
- }
- }
- public static String[] initInvValue(int size) {
- String[] values = new String[size] ;
- for(int i =0 ; i<size ; i++)
- values[i] = "1" ;
- return values;
- }
- public static void main1(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String str = null ;
- String[] infos= null;
- while (StringUtil.isNotEmpty(str = reader.readLine())) {
- str = str.replaceAll("\\s+", " ").trim();
- infos = str.split(" ");
- if (infos.length == 3 && "connect".equalsIgnoreCase(infos[0])) {
- connect(infos);
- continue ;
- }
- //MARKET#RPQUECFG#FZ_R1
- if (infos.length == 1 && "en".equalsIgnoreCase(infos[0])) {
- QueuesCfg cfg = cl.getCache("MARKET#RPQUECFG#FZ_R1", QueuesCfg.class);
- cfg.setUsed(true) ;
- cl.set("MARKET#RPQUECFG#FZ_R1", cfg) ;
- continue ;
- }
- if (infos.length == 1 && "addinv".equalsIgnoreCase(infos[0])) {
- for(int i= 0; i< 900 ;i ++) {
- String[] rpValues = initInvValue(1500 );
- cl.lPush("MARKET#UQUE#FZ_R1", rpValues);
- }
- continue ;
- }
- if (infos.length == 1 && "hget".equalsIgnoreCase(infos[0])) {
- Map<String, String> maps = cl.getMap("MARKET#TYPE");
- for (String s : maps.keySet()) {
- System.out.println(maps.get(s));
- }
- }
- if (infos.length == 1 && "hset".equalsIgnoreCase(infos[0])) {
- /*
- * if(infos.length == 4 && "hset".equalsIgnoreCase(infos[0])){
- * //cl.setMap(infos[1], infos[2], infos[3]) ;
- * cl.setMap("MARKET#TYPE", "1", "新人专享") ;
- * cl.setMap("MARKET#TYPE", "2", "老带新") ;
- * cl.setMap("MARKET#TYPE", "3", "现金奖励") ;
- * cl.setMap("MARKET#TYPE", "4", "充值返现") ; }
- */
- cl.setMap("MARKET#TYPE", "7", "国庆双倍收益");
- continue;
- }
- if (infos.length == 1 && "detail".equalsIgnoreCase(infos[0])) {
- BufferedReader b1 = new BufferedReader(new FileReader("c:\\hb.txt"));
- String c1 = null;
- while (StringUtil.isNotEmpty(c1 = b1.readLine())) {
- String[] params = c1.replaceAll("\\s+", " ").trim() .split(" ");
- modyfyDetail(params[0].trim(), params[1].trim());
- }
- }
- if (/* infos.length == 3 && */"print".equalsIgnoreCase(infos[0])) {
- BufferedReader b = new BufferedReader(new FileReader(
- "c:\\hb.txt"));
- String c = null;
- String value = null;
- while (StringUtil.isNotEmpty(c = b.readLine())) {
- String rcdCntKey = CacheKey.RP_RECORD.getKey(new String[] {
- "NFL", c.trim() });
- int cnt = (int) cl.incre(rcdCntKey, 1);
- }
- }
- }
- }
- /**
- * "http://xxxxxx/gift/rechargetrigger" 充值
- * http://xxxxxx/gift/rpsettledetail 修改流水
- * 修改 流水
- * @param object
- * @param url
- * @param method
- */
- public static void rspCall(Object object, String url, String method ) {
- String params = JsonExceptionUtil.toJsonString(object);
- String returnStr = null;
- Object obj = null;
- ResponseVo responseVo = null;
- Object dto = null;
- try {
- returnStr = RestUtilTool.sendData(url, method, params, 2000, "add", "add");
- responseVo = JsonExceptionUtil.toBean(returnStr, ResponseVo.class);
- if (responseVo.isSuccess()) {
- obj = responseVo.getData();
- System.out.println(obj.toString()) ;
- }
- } catch (Exception e) {
- e.printStackTrace() ;
- }
- if (!responseVo.isSuccess()) {
- System.out.println(responseVo.toString()) ;
- }
- }
- public static void modyfyDetail(String id,String accountNo ) {
- FpSettleDetail detail = new FpSettleDetail() ;
- detail.setId(Integer.valueOf(id)) ;
- detail.setAccountNo(accountNo);
- detail.setActiveCode("FZ");
- detail.setOverTime(DateUtil.parseDateTime("2015-11-15 00:00:00")) ;
- try {
- rspCall(detail, "http://xxxxxx/gift/rpsettledetail", "POST") ;
- } catch (Exception e) {
- System.out.println("id ==" + id) ;
- }
- }
- public static void test(String memberId ,BigDecimal amount) {
- try {
- RpReciveInput input = new RpReciveInput();
- input.setAccountNo(memberId) ;
- input.setMoney(amount) ;
- input.setDetailId("-1") ;
- String params = JsonUtil.toString(input);
- //Base64Util
- // queryForFinInfo(input);
- } catch (Exception e) {
- e.printStackTrace() ;
- }
- }
- public static String[] readTxtFile(String filePath){
- StringBuilder sb = new StringBuilder();
- try {
- String encoding="UTF-8";
- File file=new File(filePath);
- if(file.isFile() && file.exists()){ //判断文件是否存在
- InputStreamReader read = new InputStreamReader(
- new FileInputStream(file),encoding);//考虑到编码格式
- BufferedReader bufferedReader = new BufferedReader(read);
- String lineTxt = null;
- while((lineTxt = bufferedReader.readLine()) != null){
- //System.out.println(lineTxt);
- sb.append(lineTxt).append(";");
- }
- read.close();
- }else{
- System.out.println("找不到指定的文件");
- }
- } catch (Exception e) {
- System.out.println("读取文件内容出错");
- e.printStackTrace();
- }
- return sb.toString().split(";");
- }
- public static void mainXX(String[] args) throws IOException {
- String filePath = "C:\\Users\\fanghui\\Desktop\\DATA.txt";
- String[] s= readTxtFile(filePath);
- String sql = "";
- StringBuilder sb = new StringBuilder();
- int count = 0;
- for(String str : s){
- String[] subStr = str.trim().split("\t");
- String add_time = subStr[0];
- String member_id = subStr[1];
- String partner_id = subStr[2];
- String order_id = subStr[3];
- String trade_type = subStr[4];
- double trade_money = new BigDecimal(subStr[5]).doubleValue();
- String status = subStr[6];
- sql = "insert into `t_settle_recharge` ( `add_time`, `member_id`, `partner_id`, `order_id`, `trade_type`, `trade_money`, `status`) " +
- "values('"+add_time+"','"+member_id+"','"+partner_id+"','"+order_id+"','"+trade_type+"',"+trade_money+",'"+status+"');";
- //System.out.println(sql);
- sb.append(sql).append("\r\n");
- /*count++;
- if(count>200)
- return;*/
- }
- FileUtils.write(new File("C:\\Users\\fanghui\\Desktop\\bigsql.sql"), sb.toString());
- }
- public static void main(String[] args) throws IOException {
- setNetValueCache();
- }
- public static void setNetValueCache(){
- String filePath = "C:\\Users\\fanghui\\Desktop\\c1.txt";
- String[] s= readTxtFile(filePath);
- String sql = "";
- StringBuilder sb = new StringBuilder();
- for(String str : s){
- String[] subStr = str.trim().split(",");
- String member_id = subStr[0];
- String inputMoney = subStr[1];
- String totalAward = subStr[2];
- //根据该发总奖金反推此用户的总净值
- BigDecimal totalMoney = new BigDecimal(totalAward).divide(new BigDecimal(9)).multiply(new BigDecimal(5000));
- String nvKey = CacheKey.RP_NET_WORTH.getKey(new String[]{"JZN",member_id}) ; //ex: MARKET#NETWORTH##JZN#6700336
- //cl.setMap(nvKey, "field_netValueMoney", totalMoney.toString());//净值
- //cl.setMap(nvKey, "field_ownAwardMoney", totalAward);//总共已领取金额
- System.out.println(member_id+", jinzhi: "+totalMoney.toString()+" ,总共已领取金额 : "+totalAward);
- /*String netValueMoney = (String) cl.getMapValue(nvKey, "field_netValueMoney");//从缓存中取用户已有净值
- String ownAwardMoney = (String) cl.getMapValue(nvKey, "field_ownAwardMoney");//从缓存中取用户已领取金额
- if(netValueMoney==null){ //缓存中无净值时,可认为是用户首次访问系统[如果缓存系统挂了,应该执行后门程序去查库更新缓存值]
- cl.setMap(nvKey, "field_netValueMoney", "0");//净值
- netValueMoney = "0";
- }
- if(ownAwardMoney == null ){
- cl.setMap(nvKey, "field_ownAwardMoney", "0");//总共已领取金额
- ownAwardMoney = "0";
- }
- */
- }
- }
- }
RedisCacheTool参考其中的文件读写功能的更多相关文章
- JS封装插件:实现文件读写功能
scripting.FileSystemObject是一个可以实现文件读写的COM组件,由于COM组件可以被跨语言调用,因此可以选择像vbs或者JS这种脚本语言调用,下面我就使用该COM组件封装了一个 ...
- [js高手之路]node js系列课程-创建简易web服务器与文件读写
web服务器至少有以下几个特点: 1.24小时不停止的工作,也就是说这个进程要常驻在内存中 2.24小时在某一端口监听,如: http://localhost:8080, www服务器默认端口80 3 ...
- java byte【】数组与文件读写(增加新功能)
今天在测试直接写的文章: java byte[]数组与文件读写 时,想调用FileHelper类对字节数组以追加的方式写文件,结果无论怎样竟然数据录入不全,重新看了下文件的追加模式,提供了两种方式: ...
- [转]Android - 文件读写操作 总结
转自:http://blog.csdn.net/ztp800201/article/details/7322110 Android - 文件读写操作 总结 分类: Android2012-03-05 ...
- Python之文件读写
本节内容: I/O操作概述 文件读写实现原理与操作步骤 文件打开模式 Python文件操作步骤示例 Python文件读取相关方法 文件读写与字符编码 一.I/O操作概述 I/O在计算机中是指Input ...
- 通过文件读写方式实现Matlab和Modelsim的联合仿真
虽然Modelsim的功能非常强大,仿真的波形可以以多种形式进行显示,但是当涉及到数字信号处理的算法的仿真验证的时候,则显得有点不足.而进行数字信号处理是Matlab的强项,不但有大量的关于数字信号处 ...
- python之文件读写详解
打开文件 函数open() 参数说明: file:文件路径 mode: 文件的读写方式,默认'r',只读方式: buffering:设置缓冲策略,0用于二进制文件,1为行缓冲,用于文本模式:默认二进制 ...
- C#使用FileSystemWatcher控件实现的文件监控功能示例
本文实例讲述了C#使用FileSystemWatcher控件实现的文件监控功能.分享给大家供大家参考,具体如下: FileSystemWatcher 可以使用FileSystemWatcher组件监视 ...
- python的文件读写笔记
读写文件是最常见的IO操作.Python内置了读写文件的函数,用法和C是兼容的. 读写文件前,我们先必须了解一下,在磁盘上读写文件的功能都是由操作系统提供的,现代操作系统不允许普通的程序直接操作磁盘, ...
随机推荐
- 【转】Android使用Log4j例子
Step 1 Download Log4J library from http://logging.apache.org/log4j/1.2/download.html Step 2 Configur ...
- 笨小猴 2008年NOIP全国联赛提高组
题目描述 Description 笨小猴的词汇量很小,所以每次做英语选择题的时候都很头疼.但是他找到了一种方法,经试验证明,用这种方法去选择选项的时候选对的几率非常大! 这种方法的具体描述如下:假设m ...
- POJ3352 Road Construction(边双连通分量)
...
- bzoj 1061 志愿者招募(最小费用最大流)
[Noi2008]志愿者招募 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 3792 Solved: 2314[Submit][Status][Di ...
- phpwind数据同步本地之后板块排版乱
排版紊乱的问题一般是css文件的问题 解决思路 1.打开chrome调用F12,查看是不是css文件没有获取. 2.如果没有获取到的话检查css文件的路径. 在本例中phpwind数据同步到本地之后, ...
- 升级win10的理由
微软也没给我钱,我免费给它打了次广告. 我还是非常喜欢linux的,无奈公司深度依赖windows. 废话不多说,直接进入主题: [开机速度] 这里先说句题外话,不那么缺钱的兄弟,一定要去换一块SSD ...
- linux下crontab定时执行本地脚本和定时访问指定url
https://my.oschina.net/u/2487410/blog/683308 使用linux curl命令讲解:http://www.linuxdiyf.com/linux/2800.ht ...
- dom4j测试
book.xml <?xml version="1.0" encoding="UTF-8"?><books><book>&l ...
- dump java
http://www.gamlor.info/wordpress/2011/09/visualvm/ https://visualvm.java.net/zh_CN/gettingstarted.ht ...
- Java 实现学生信息管理系统
编写一个简单的学生管理信息系统. 在oracle中设计一张学生表,以学号作为关键字. 其他学生信息有:姓名.手机号. 在进入系统时,显示如下菜单: ************************** ...