Package org.redisson.api.mapreduce
Interface RCollectionMapReduce<VIn,KOut,VOut>
-
- Type Parameters:
VIn
- input valueKOut
- output keyVOut
- output value
- All Superinterfaces:
RMapReduceExecutor<VIn,KOut,VOut>
- All Known Implementing Classes:
RedissonCollectionMapReduce
public interface RCollectionMapReduce<VIn,KOut,VOut> extends RMapReduceExecutor<VIn,KOut,VOut>
MapReduce allows to process large amount of data stored inRSet
,RList
,RSetCache
,RScoredSortedSet
,RSortedSet
and others using Mapper, Reducer and/or Collator tasks launched across Redisson Nodes.Usage example:
public class WordMapper implements RCollectionMapper<String, String, Integer> { public void map(String value, RCollector<String, Integer> collector) { String[] words = value.split("[^a-zA-Z]"); for (String word : words) { collector.emit(word, 1); } } } public class WordReducer implements RReducer<String, Integer> { public Integer reduce(String reducedKey, Iterator<Integer> iter) { int sum = 0; while (iter.hasNext()) { Integer i = (Integer) iter.next(); sum += i; } return sum; } } public class WordCollator implements RCollator<String, Integer, Integer> { public Integer collate(Map<String, Integer> resultMap) { int result = 0; for (Integer count : resultMap.values()) { result += count; } return result; } } RList<String> list = redisson.getList("myWords"); Map<String, Integer> wordsCount = list.<String, Integer>mapReduce() .mapper(new WordMapper()) .reducer(new WordReducer()) .execute(); Integer totalCount = list.<String, Integer>mapReduce() .mapper(new WordMapper()) .reducer(new WordReducer()) .execute(new WordCollator());
- Author:
- Nikita Koksharov
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description RCollectionMapReduce<VIn,KOut,VOut>
mapper(RCollectionMapper<VIn,KOut,VOut> mapper)
Setup Mapper objectRCollectionMapReduce<VIn,KOut,VOut>
reducer(RReducer<KOut,VOut> reducer)
Setup Reducer objectRCollectionMapReduce<VIn,KOut,VOut>
timeout(long timeout, TimeUnit unit)
Defines timeout for MapReduce process-
Methods inherited from interface org.redisson.api.mapreduce.RMapReduceExecutor
execute, execute, execute, executeAsync, executeAsync, executeAsync
-
-
-
-
Method Detail
-
timeout
RCollectionMapReduce<VIn,KOut,VOut> timeout(long timeout, TimeUnit unit)
Defines timeout for MapReduce process- Parameters:
timeout
- for processunit
- of timeout- Returns:
- self instance
-
mapper
RCollectionMapReduce<VIn,KOut,VOut> mapper(RCollectionMapper<VIn,KOut,VOut> mapper)
Setup Mapper object- Parameters:
mapper
- used during MapReduce- Returns:
- self instance
-
-