use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class RedisHashImpl method get.
@Override
public String get(String key, String field) {
StopWatch watch = new StopWatch();
PoolItem<RedisConnection> item = redis.pool.borrowItem();
try {
RedisConnection connection = item.resource;
connection.write(HGET, encode(key), encode(field));
return decode(connection.readBulkString());
} catch (IOException e) {
item.broken = true;
throw new UncheckedIOException(e);
} finally {
redis.pool.returnItem(item);
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("redis", elapsedTime, 1, 0);
logger.debug("hget, key={}, field={}, elapsedTime={}", key, field, elapsedTime);
redis.checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class RedisImpl method set.
public void set(String key, byte[] value, Duration expiration) {
StopWatch watch = new StopWatch();
PoolItem<RedisConnection> item = pool.borrowItem();
try {
RedisConnection connection = item.resource;
connection.write(Protocol.Command.SETEX, encode(key), encode(expiration.getSeconds()), value);
connection.readSimpleString();
} catch (IOException e) {
item.broken = true;
throw new UncheckedIOException(e);
} finally {
pool.returnItem(item);
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("redis", elapsedTime, 0, 1);
logger.debug("set, key={}, value={}, expiration={}, elapsedTime={}", key, new BytesParam(value), expiration, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class RedisImpl method increaseBy.
@Override
public long increaseBy(String key, long increment) {
StopWatch watch = new StopWatch();
PoolItem<RedisConnection> item = pool.borrowItem();
try {
RedisConnection connection = item.resource;
connection.write(Protocol.Command.INCRBY, encode(key), encode(increment));
return connection.readLong();
} catch (IOException e) {
item.broken = true;
throw new UncheckedIOException(e);
} finally {
pool.returnItem(item);
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("redis", elapsedTime, 0, 1);
logger.debug("increaseBy, key={}, increment={}, elapsedTime={}", key, increment, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class RedisImpl method getBytes.
public byte[] getBytes(String key) {
StopWatch watch = new StopWatch();
PoolItem<RedisConnection> item = pool.borrowItem();
try {
RedisConnection connection = item.resource;
connection.write(Protocol.Command.GET, encode(key));
return connection.readBulkString();
} catch (IOException e) {
item.broken = true;
throw new UncheckedIOException(e);
} finally {
pool.returnItem(item);
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("redis", elapsedTime, 1, 0);
logger.debug("get, key={}, elapsedTime={}", key, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
use of core.framework.util.StopWatch in project core-ng-project by neowu.
the class RedisImpl method multiSet.
public void multiSet(Map<String, byte[]> values, Duration expiration) {
StopWatch watch = new StopWatch();
byte[] expirationValue = encode(expiration.getSeconds());
PoolItem<RedisConnection> item = pool.borrowItem();
int size = values.size();
try {
RedisConnection connection = item.resource;
for (Map.Entry<String, byte[]> entry : values.entrySet()) {
connection.write(Protocol.Command.SETEX, encode(entry.getKey()), expirationValue, entry.getValue());
}
connection.readAll(size);
} catch (IOException e) {
item.broken = true;
throw new UncheckedIOException(e);
} finally {
pool.returnItem(item);
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("redis", elapsedTime, 0, size);
logger.debug("mset, values={}, expiration={}, elapsedTime={}", values, expiration, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
Aggregations