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(" Successful connection [" + 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", " Exclusive for new people ") ;
* cl.setMap("MARKET#TYPE", "2", " Old brings new ") ;
* cl.setMap("MARKET#TYPE", "3", " Cash reward ") ;
* cl.setMap("MARKET#TYPE", "4", " Recharge and cash back ") ; }
*/
cl.setMap("MARKET#TYPE", "7", " National Day double benefits ");
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" Recharge
* http://xxxxxx/gift/rpsettledetail Modify flow
* modify Running water
* @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()){ // Judge whether the file exists
InputStreamReader read = new InputStreamReader(
new FileInputStream(file),encoding);// Considering the encoding format
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(" The specified file could not be found ");
}
} catch (Exception e) {
System.out.println(" Error reading file contents ");
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]; // According to the total bonus, the total net value of this user is deduced
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());// Net worth
//cl.setMap(nvKey, "field_ownAwardMoney", totalAward);// Total amount received
System.out.println(member_id+", jinzhi: "+totalMoney.toString()+" , Total amount received : "+totalAward); /*String netValueMoney = (String) cl.getMapValue(nvKey, "field_netValueMoney");// Get the net value of the user from the cache
String ownAwardMoney = (String) cl.getMapValue(nvKey, "field_ownAwardMoney");// Get the amount that the user has claimed from the cache
if(netValueMoney==null){ // When there is no net value in the cache , It can be considered as the first time a user has visited the system [ If the caching system goes down , The backdoor program should be executed to check the database and update the cache value ]
cl.setMap(nvKey, "field_netValueMoney", "0");// Net worth
netValueMoney = "0";
} if(ownAwardMoney == null ){
cl.setMap(nvKey, "field_ownAwardMoney", "0");// Total amount received
ownAwardMoney = "0";
}
*/
} }
}

RedisCacheTool Refer to the file read and write function for more related articles

  1. JS Package plug-ins : Realize the function of reading and writing files

    scripting.FileSystemObject Is a file can read and write COM Components , because COM Components can be called across languages , So you can choose something like vbs perhaps JS This scripting language calls , Now I'll use this COM The component encapsulates a ...

  2. [js Master's Road ]node js Series courses - Create simple web Server and file reading and writing

    web The server has at least the following features : 1.24 Hours of nonstop work , That is to say, the process should be resident in memory 2.24 Listen on a certain port , Such as : http://localhost:8080, www Server default port 80 3 ...

  3. java byte【】 Array and file read and write ( Add new features )

    Today, I'm testing the direct writing article : java byte[] Array and file read and write when , Want to call FileHelper Class appends the byte array to a file , No matter what, the data entry is incomplete , Look at the file append mode again , It provides two ways : ...

  4. [ turn ]Android - File read and write operations summary

      from :http://blog.csdn.net/ztp800201/article/details/7322110 Android - File read and write operations summary classification : Android2012-03-05 ...

  5. Python Reading and writing of documents

    Content of this section : I/O Operation Overview File read and write implementation principle and operation steps File open mode Python Example of file operation steps Python File reading related methods File reading and writing and character coding One .I/O Operation Overview I/O In computer, it means Input ...

  6. It is realized by reading and writing files Matlab and Modelsim Joint simulation of

    although Modelsim It's very powerful , The simulated waveform can be displayed in various forms , But when it comes to the simulation of digital signal processing algorithm , It seems a little inadequate . And digital signal processing is the key Matlab The strengths of , There is not only a lot of information about digital signals ...

  7. python Reading and writing of documents

    Open file function open() Parameter description : file: File path mode: How to read and write files , Default 'r', Read only mode : buffering: Set buffer strategy ,0 For binary files ,1 Buffering for rows , For text mode : Default binary ...

  8. C# Use FileSystemWatcher Control to achieve file monitoring function example

    This article gives an example of C# Use FileSystemWatcher Control to realize the file monitoring function . Share with you for your reference , As follows : FileSystemWatcher have access to FileSystemWatcher Component monitoring ...

  9. python Read and write your notes

    Reading and writing files is the most common IO operation .Python Built in functions for reading and writing files , Usage and C Is compatible . Before reading and writing the document , We must first understand , The function of reading and writing files on disk is provided by the operating system , The modern operating system does not allow ordinary programs to operate the disk directly , ...

Random recommendation

  1. .NET LINQ Data sorting

    Data sorting       The sort operation sorts the elements of a sequence by one or more properties . The first sort condition performs the primary sort on the elements . By specifying the second sort condition , You can sort the elements in each major sort group .   Method Method name explain C# check ...

  2. jQuery Plug-in development --( turn )

    1, Start You can do this by jQuery.fn Add a new function to write jQuery plug-in unit . The name of the attribute is the name of your plug-in : jQuery.fn.myPlugin = function(){ // Start writing your code ! ...

  3. Xml One of the ways to use file manipulation :

    XmlNodeList students = doc.DocumentElement.ChildNodes;//Student Node collection foreach (XmlNode stu in students ...

  4. &lt;!DOCTYPE&gt; The understanding of the

    [[ from <!DOCTYPE> Deep understanding of labels ]] Preface : Asked today “ Have you had a thorough understanding of <!DOCTYPE> label ?”, For a moment , Because in the beginning W3cschool I've seen it on the Internet ...

  5. LINUX Common configurations and commands

    One .   Fedora The system configuration 1.      [ Set the nic IP] Steps are as follows : 1)     use root The user login , open /etc/sysconfig/network-scripts/ifcfg-eth0 writing ...

  6. Eclipse c++ Environment building And load OpenCV library 2015 newest

    C++: Search for Eclipse c++ that will do Pay attention to the new version mingw Installers , To install : 1.mingw-developer-toolkit 2.mingw32-base 3.mingw32-gcc-g++ ...

  7. Centos7 Install configuration on RabbitMQ

    Preface :  Recently, the server has been set up rabbitmq, I found a lot of tutorials on the Internet , A pit with a lot of ash . Now I finally got out of the pit . Write it down , Avoid falling into the pit next time   Okay , I don't say much nonsense , Let's get down to business One . install Erl ...

  8. Spring Boot( 8、 ... and ):RabbitMQ Detailed explanation

    RabbitMQ It's a message queue , It is mainly used to realize asynchronous and decoupling of applications , It can also buffer messages , The role of message distribution . Message middleware is used more and more by Internet companies , I just saw the news that Ali will RocketMQ Donated to ...

  9. Python Sets and their operations

    Catalog aggregate (set) Set creation Operations on collections The operation of sets Subsets and supersets aggregate (set) A set is made up of different variables hash The value of , All the values in it are unique , It's also out of order Set creation >>>set_ ...

  10. Xcode - Because the certificate problem often reported those mistakes

    1. Confirm whether the certificate is a development certificate , If you are publishing a certificate, this prompt will appear . 2. The certificate is invalid , Go to the developer center and regenerate a . 3. The package identifier is not consistent with the package identifier contained in the description file , Just change it according to its instructions , Better not Fix ...