本文整理汇总了Java中redis.clients.util.RedisOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java RedisOutputStream类的具体用法?Java RedisOutputStream怎么用?Java RedisOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RedisOutputStream类属于redis.clients.util包,在下文中一共展示了RedisOutputStream类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: sendCommand
import redis.clients.util.RedisOutputStream; //导入依赖的package包/类
private static void sendCommand(final RedisOutputStream os, final byte[] command, final byte[]... args) {
try {
os.write(ASTERISK_BYTE);
os.writeIntCrLf(args.length + 1);
os.write(DOLLAR_BYTE);
os.writeIntCrLf(command.length);
os.write(command);
os.writeCrLf();
for (final byte[] arg : args) {
os.write(DOLLAR_BYTE);
os.writeIntCrLf(arg.length);
os.write(arg);
os.writeCrLf();
}
} catch (IOException e) {
throw new JedisConnectionException(e);
}
}
开发者ID:qq1588518,项目名称:JRediClients,代码行数:20,代码来源:Protocol.java
示例2: buildACommand
import redis.clients.util.RedisOutputStream; //导入依赖的package包/类
@Test
public void buildACommand() throws IOException {
PipedInputStream pis = new PipedInputStream();
BufferedInputStream bis = new BufferedInputStream(pis);
PipedOutputStream pos = new PipedOutputStream(pis);
RedisOutputStream ros = new RedisOutputStream(pos);
Protocol.sendCommand(ros, Protocol.Command.GET, "SOMEKEY".getBytes(Protocol.CHARSET));
ros.flush();
pos.close();
String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n";
int b;
StringBuilder sb = new StringBuilder();
while ((b = bis.read()) != -1) {
sb.append((char) b);
}
assertEquals(expectedCommand, sb.toString());
}
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:ProtocolTest.java
示例3: writeOverflow
import redis.clients.util.RedisOutputStream; //导入依赖的package包/类
@Test(expected = IOException.class)
public void writeOverflow() throws IOException {
RedisOutputStream ros = new RedisOutputStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
throw new IOException("thrown exception");
}
});
ros.write(new byte[8191]);
try {
ros.write((byte) '*');
} catch (IOException ioe) {
}
ros.write((byte) '*');
}
开发者ID:qq1588518,项目名称:JRediClients,代码行数:22,代码来源:ProtocolTest.java
示例4: connect
import redis.clients.util.RedisOutputStream; //导入依赖的package包/类
public void connect() {
if (!isConnected()) {
try {
socket = new Socket();
// ->@wjw_add
socket.setReuseAddress(true);
socket.setKeepAlive(true); // Will monitor the TCP connection is
// valid
socket.setTcpNoDelay(true); // Socket buffer Whetherclosed, to
// ensure timely delivery of data
socket.setSoLinger(true, 0); // Control calls close () method,
// the underlying socket is closed
// immediately
// <[email protected]_add
socket.connect(new InetSocketAddress(host, port), connectionTimeout);
socket.setSoTimeout(soTimeout);
outputStream = new RedisOutputStream(socket.getOutputStream());
inputStream = new RedisInputStream(socket.getInputStream());
} catch (IOException ex) {
broken = true;
throw new JedisConnectionException(ex);
}
}
}
开发者ID:x7-framework,项目名称:x7,代码行数:26,代码来源:Connection.java
示例5: sendCommand
import redis.clients.util.RedisOutputStream; //导入依赖的package包/类
private static void sendCommand(final RedisOutputStream os, final byte[] command,
final byte[]... args) {
try {
os.write(ASTERISK_BYTE);
os.writeIntCrLf(args.length + 1);
os.write(DOLLAR_BYTE);
os.writeIntCrLf(command.length);
os.write(command);
os.writeCrLf();
for (final byte[] arg : args) {
os.write(DOLLAR_BYTE);
os.writeIntCrLf(arg.length);
os.write(arg);
os.writeCrLf();
}
} catch (IOException e) {
throw new JedisConnectionException(e);
}
}
开发者ID:x7-framework,项目名称:x7,代码行数:21,代码来源:Protocol.java
示例6: connect
import redis.clients.util.RedisOutputStream; //导入依赖的package包/类
public void connect() {
if (!isConnected()) {
try {
socket = new Socket();
//->@wjw_add
socket.setReuseAddress(true);
socket.setKeepAlive(true); //Will monitor the TCP connection is valid
socket.setTcpNoDelay(true); //Socket buffer Whetherclosed, to ensure timely delivery of data
socket.setSoLinger(true,0); //Control calls close () method, the underlying socket is closed immediately
//<[email protected]_add
socket.connect(new InetSocketAddress(host, port), timeout);
socket.setSoTimeout(timeout);
outputStream = new RedisOutputStream(socket.getOutputStream());
inputStream = new RedisInputStream(socket.getInputStream());
} catch (IOException ex) {
throw new JedisConnectionException(ex);
}
}
}
开发者ID:wjw465150,项目名称:shiro-redis,代码行数:21,代码来源:Connection.java
示例7: sendCommand
import redis.clients.util.RedisOutputStream; //导入依赖的package包/类
private static void sendCommand(final RedisOutputStream os,
final byte[] command, final byte[]... args) {
try {
os.write(ASTERISK_BYTE);
os.writeIntCrLf(args.length + 1);
os.write(DOLLAR_BYTE);
os.writeIntCrLf(command.length);
os.write(command);
os.writeCrLf();
for (final byte[] arg : args) {
os.write(DOLLAR_BYTE);
os.writeIntCrLf(arg.length);
os.write(arg);
os.writeCrLf();
}
} catch (IOException e) {
throw new JedisConnectionException(e);
}
}
开发者ID:wjw465150,项目名称:shiro-redis,代码行数:21,代码来源:Protocol.java
示例8: sendCommand
import redis.clients.util.RedisOutputStream; //导入依赖的package包/类
private static void sendCommand(RedisOutputStream os, byte[] command,
byte[]... args) {
try {
// 构造"Redis二进制协议"格式内容
os.write(ASTERISK_BYTE);
os.writeIntCrLf(args.length + 1);
os.write(DOLLAR_BYTE);
os.writeIntCrLf(command.length);
os.write(command);
os.writeCrLf();
for (byte[] arg : args) {
os.write(DOLLAR_BYTE);
os.writeIntCrLf(arg.length);
os.write(arg);
os.writeCrLf();
}
} catch (IOException e) {
// 抛出"Redis连接异常"
throw new JedisConnectionException(e);
}
}
开发者ID:EdwardLee03,项目名称:jedis-sr,代码行数:23,代码来源:Protocol.java
示例9: measureCommand
import redis.clients.util.RedisOutputStream; //导入依赖的package包/类
private static long measureCommand() throws Exception {
long duration = 0;
byte[] KEY = "123456789".getBytes();
byte[] VAL = "FooBar".getBytes();
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
RedisOutputStream out = new RedisOutputStream(new ByteArrayOutputStream(8192));
long start = System.nanoTime();
Protocol.sendCommand(out, Protocol.Command.SET, KEY, VAL);
duration += (System.nanoTime() - start);
}
return duration;
}
开发者ID:qq1588518,项目名称:JRediClients,代码行数:16,代码来源:ProtocolBenchmark.java
示例10: connect
import redis.clients.util.RedisOutputStream; //导入依赖的package包/类
public void connect() {
if (!isConnected()) {
try {
socket = new Socket();
// ->@wjw_add
socket.setReuseAddress(true);
socket.setKeepAlive(true); // Will monitor the TCP connection is
// valid
socket.setTcpNoDelay(true); // Socket buffer Whetherclosed, to
// ensure timely delivery of data
socket.setSoLinger(true, 0); // Control calls close () method,
// the underlying socket is closed
// immediately
// <[email protected]_add
socket.connect(new InetSocketAddress(host, port), connectionTimeout);
socket.setSoTimeout(soTimeout);
outputStream = new RedisOutputStream(socket.getOutputStream());
inputStream = new RedisInputStream(socket.getInputStream());
} catch (IOException ex) {
UsefulDataCollector.collectException(ex, getHostPort(), System.currentTimeMillis());
broken = true;
throw new JedisConnectionException(ex);
}
}
}
开发者ID:sohutv,项目名称:cachecloud,代码行数:28,代码来源:Connection.java
示例11: connect
import redis.clients.util.RedisOutputStream; //导入依赖的package包/类
/**
* 连接到Redis服务器。
*
* <pre>
* 分2个步骤:
* 1. 若当前的链接套接字还打开着,则直接返回;
* 2. 否则,创建一条新的套接字链接。
* </pre>
*/
public void connect() {
if (!this.isConnected()) {
// 当前的链接套接字已被关闭,需要重新建立一条新的链接
try {
socket = new Socket();
socket.setReuseAddress(true);
// Will monitor the TCP connection is valid (使用长连接技术)
socket.setKeepAlive(true);
// Socket buffer Whether closed, to ensure timely delivery of data (确保数据实时发送)
socket.setTcpNoDelay(true);
// Control calls close() method, the underlying socket is closed immediately
// (即使背后的套接字被瞬间关闭,也确保close()被调用)
socket.setSoLinger(true, 0);
// 创建一条新的连接到后端Redis服务器的链接
// TODO 连接超时与读取超时,使用同一个参数值不合理!
socket.connect(new InetSocketAddress(host, port), timeout);
socket.setSoTimeout(timeout);
outputStream = new RedisOutputStream(socket.getOutputStream());
inputStream = new RedisInputStream(socket.getInputStream());
} catch (IOException ex) {
// 创建新的套接字时,发生了异常
broken = true;
throw new JedisConnectionException(ex);
}
}
}
开发者ID:EdwardLee03,项目名称:jedis-sr,代码行数:38,代码来源:Connection.java
注:本文中的redis.clients.util.RedisOutputStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论