use of redis.clients.jedis.ScanParams in project apex-malhar by apache.
the class RedisInputOperatorTest method testRecoveryAndIdempotency.
@Test
public void testRecoveryAndIdempotency() throws Exception {
this.operatorStore = new RedisStore();
this.testStore = new RedisStore();
testStore.connect();
ScanParams params = new ScanParams();
params.count(1);
testStore.put("test_abc", "789");
testStore.put("test_def", "456");
testStore.put("test_ghi", "123");
RedisKeyValueInputOperator operator = new RedisKeyValueInputOperator();
operator.setWindowDataManager(new FSWindowDataManager());
operator.setStore(operatorStore);
operator.setScanCount(1);
Attribute.AttributeMap attributeMap = new Attribute.AttributeMap.DefaultAttributeMap();
CollectorTestSink<Object> sink = new CollectorTestSink<Object>();
operator.outputPort.setSink(sink);
OperatorContext context = mockOperatorContext(1, attributeMap);
try {
operator.setup(context);
operator.beginWindow(1);
operator.emitTuples();
operator.endWindow();
int numberOfMessagesInWindow1 = sink.collectedTuples.size();
sink.collectedTuples.clear();
operator.beginWindow(2);
operator.emitTuples();
operator.endWindow();
int numberOfMessagesInWindow2 = sink.collectedTuples.size();
sink.collectedTuples.clear();
// failure and then re-deployment of operator
// Re-instantiating to reset values
operator = new RedisKeyValueInputOperator();
operator.setWindowDataManager(new FSWindowDataManager());
operator.setStore(operatorStore);
operator.setScanCount(1);
operator.outputPort.setSink(sink);
operator.setup(context);
Assert.assertEquals("largest recovery window", 2, operator.getWindowDataManager().getLargestCompletedWindow());
operator.beginWindow(1);
operator.emitTuples();
operator.emitTuples();
operator.endWindow();
Assert.assertEquals("num of messages in window 1", numberOfMessagesInWindow1, sink.collectedTuples.size());
sink.collectedTuples.clear();
operator.beginWindow(2);
operator.emitTuples();
operator.endWindow();
Assert.assertEquals("num of messages in window 2", numberOfMessagesInWindow2, sink.collectedTuples.size());
} finally {
for (Object e : sink.collectedTuples) {
KeyValPair<String, String> entry = (KeyValPair<String, String>) e;
testStore.remove(entry.getKey());
}
sink.collectedTuples.clear();
operator.getWindowDataManager().committed(5);
operator.teardown();
}
}
use of redis.clients.jedis.ScanParams in project apex-malhar by apache.
the class AbstractRedisInputOperator method setup.
@Override
public void setup(OperatorContext context) {
super.setup(context);
sleepTimeMillis = context.getValue(context.SPIN_MILLIS);
getWindowDataManager().setup(context);
this.context = context;
scanOffset = 0;
scanComplete = false;
scanParameters = new ScanParams();
scanParameters.count(scanCount);
// For the 1st window after checkpoint, windowID - 1 would not have recovery
// offset stored in windowDataManager
// But recoveryOffset is non-transient, so will be recovered with
// checkPointing
// Offset recovery from idempotency storage can be skipped in this case
scanOffset = recoveryState.scanOffsetAtBeginWindow;
skipOffsetRecovery = true;
}
use of redis.clients.jedis.ScanParams in project xian by happyyangyuan.
the class CacheScanUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String pattern = msg.getArgMap().get("pattern").toString();
int count = msg.get("count", Integer.class, THRESHOLD_VALUE);
String cursor = msg.getArgMap().get("cursor").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
JSONObject jsonObject = Redis.call(cacheConfigBean, jedis -> {
JSONObject _jsonObject = new JSONObject();
ScanParams params = new ScanParams().match(pattern).count(count);
ScanResult<String> scans = jedis.scan(cursor, params);
// 如果服务器向客户端返回 0 的游标时则表示迭代结束
_jsonObject.put("cursor", scans.getStringCursor());
_jsonObject.put("result", scans.getResult());
return _jsonObject;
});
return UnitResponse.success(jsonObject);
} catch (Exception e) {
return UnitResponse.exception(e);
}
}
use of redis.clients.jedis.ScanParams in project leshan by eclipse.
the class RedisSecurityStore method getAll.
@Override
public Collection<SecurityInfo> getAll() {
try (Jedis j = pool.getResource()) {
ScanParams params = new ScanParams().match(SEC_EP + "*").count(100);
Collection<SecurityInfo> list = new LinkedList<>();
String cursor = "0";
do {
ScanResult<byte[]> res = j.scan(cursor.getBytes(), params);
for (byte[] key : res.getResult()) {
byte[] element = j.get(key);
list.add(deserialize(element));
}
cursor = res.getStringCursor();
} while (!"0".equals(cursor));
return list;
}
}
use of redis.clients.jedis.ScanParams in project new-cloud by xie-summer.
the class HashesCommandsTest method hscanCount.
@Test
public void hscanCount() {
ScanParams params = new ScanParams();
params.count(2);
for (int i = 0; i < 10; i++) {
jedis.hset("foo", "a" + i, "a" + i);
}
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", SCAN_POINTER_START, params);
assertFalse(result.getResult().isEmpty());
// binary
params = new ScanParams();
params.count(2);
jedis.hset(bfoo, bbar, bcar);
jedis.hset(bfoo, bbar1, bcar);
jedis.hset(bfoo, bbar2, bcar);
jedis.hset(bfoo, bbar3, bcar);
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo, SCAN_POINTER_START_BINARY, params);
assertFalse(bResult.getResult().isEmpty());
}
Aggregations