Revision 43141
Added by Eri Katsari almost 8 years ago
SourceBuildMapper.java | ||
---|---|---|
8 | 8 |
import org.apache.hadoop.io.Text; |
9 | 9 |
import org.apache.hadoop.mapreduce.Mapper; |
10 | 10 |
import org.apache.log4j.Logger; |
11 |
import redis.clients.jedis.HostAndPort; |
|
11 | 12 |
import redis.clients.jedis.Jedis; |
13 |
import redis.clients.jedis.JedisCluster; |
|
12 | 14 |
import redis.clients.jedis.JedisPool; |
13 | 15 |
import redis.clients.jedis.JedisSentinelPool; |
14 | 16 |
import redis.clients.jedis.exceptions.JedisException; |
... | ... | |
64 | 66 |
redisHost = context.getConfiguration().get("lod.redisHost"); |
65 | 67 |
redisPort = Integer.parseInt(context.getConfiguration().get("lod.redisPort")); |
66 | 68 |
|
67 |
// |
|
68 |
// pool = new JedisPool(redisHost, redisPort); |
|
69 | 69 |
|
70 |
Set<String> sentinels = new HashSet<>(); |
|
71 |
sentinels.add("master:26379"); |
|
70 |
// pool = new JedisPool(redisHost, red |
|
71 |
|
|
72 |
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>(); |
|
73 |
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7379)); |
|
74 |
JedisCluster jc = new JedisCluster(jedisClusterNodes); |
|
75 |
jc.set("slave-1", "26379"); |
|
76 |
jc.set("slave-2", "26379"); |
|
77 |
|
|
78 |
/* Set<String> sentinels = new HashSet<>(); |
|
72 | 79 |
sentinels.add("slave-1:26379"); |
73 | 80 |
sentinels.add("slave-2:26379"); |
74 |
|
|
75 | 81 |
pool = new JedisSentinelPool(redisHost, sentinels); |
76 | 82 |
|
83 |
*/ |
|
84 |
/* |
|
85 |
JedisCluster jc = new JedisCluster(sentinels);*/ |
|
77 | 86 |
|
78 | 87 |
} |
79 | 88 |
|
... | ... | |
142 | 151 |
} |
143 | 152 |
|
144 | 153 |
private void writeToRedis(String key, String value) throws Exception { |
145 |
//get a jedis connection jedis connection pool |
|
146 | 154 |
|
147 | 155 |
Jedis jedis = pool.getResource(); |
148 | 156 |
try { |
149 | 157 |
//save to redis |
150 |
jedis.sadd(key, value); |
|
158 |
|
|
159 |
// jedis.sadd(key, value); |
|
160 |
|
|
161 |
jedis.set(key, value); |
|
162 |
|
|
151 | 163 |
log.info("Writing out to redis " + key + " , " + value); |
152 |
//here check |
|
153 |
//Set members = jedis.smembers(key); |
|
154 | 164 |
|
155 |
// jedis.hmset(key, Fields.asMap().); |
|
156 | 165 |
|
157 |
//after saving the data, lets retrieve them to be sure that it has really added in redis |
|
158 |
/* Map<String, String> retrieveMap = jedis.hgetAll(key); |
|
159 |
for (String keyMap : retrieveMap.keySet()) { |
|
160 |
System.out.println(keyMap + " " + retrieveMap.get(keyMap)); |
|
161 |
}*/ |
|
162 |
|
|
163 | 166 |
} catch (JedisException e) { |
164 | 167 |
|
165 | 168 |
log.error("Error writing entity to Redis", e); |
... | ... | |
177 | 180 |
} |
178 | 181 |
|
179 | 182 |
|
180 |
|
|
181 |
|
|
182 |
|
|
183 | 183 |
@Override |
184 | 184 |
protected void cleanup(Context context) throws IOException, InterruptedException { |
185 | 185 |
|
186 | 186 |
super.cleanup(context); |
187 |
//pool.destroy(); |
|
187 | 188 |
} |
188 | 189 |
|
189 | 190 |
public Logger getLog() { |
... | ... | |
209 | 210 |
public void setRedisPort(Integer redisPort) { |
210 | 211 |
this.redisPort = redisPort; |
211 | 212 |
} |
212 |
|
|
213 | 213 |
|
214 |
|
|
214 | 215 |
public LodConfiguration getLodConfiguration() { |
215 | 216 |
return lodConfiguration; |
216 | 217 |
} |
Also available in: Unified diff