Kettle调用Redis

Posted on Posted in kettle示例

概述

Redis作为一个开源免费,高性能的kv数据库,官方称号称能够达到10w+的读写速度;本文讲解Redis如何与kettle结合, 
 

添加jedis基础包

默认etl不支持redis调用,需要将jedis-3.1.0.jar包到${etl_root}\lib目录下;

编写步骤2:java代码

import redis.clients.jedis.Jedis;
private Jedis jedis=null;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
if (first){
  first = false;
/*connect to redis server*/
 //连接本地的 Redis 服务
     jedis = new Jedis("localhost");
logBasic("Connection to server sucessfully");
      //查看服务是否运行
logBasic("Server is running: "+jedis.ping());
}
Object[] r = getRow();
if (r == null) {
  setOutputDone();
  return false;
}
    r = createOutputRow(r, data.outputRowMeta.size());
    String v=jedis.get("k1");
    // Set a value in a new output field
    get(Fields.Out, "k1").setValue(r, v);
// Send the row on to the next step.
    putRow(data.outputRowMeta, r);
return true;
}

编写步骤3:写日志