• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java RedisInputStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中redis.clients.util.RedisInputStream的典型用法代码示例。如果您正苦于以下问题:Java RedisInputStream类的具体用法?Java RedisInputStream怎么用?Java RedisInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RedisInputStream类属于redis.clients.util包,在下文中一共展示了RedisInputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: processError

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static void processError(final RedisInputStream is) {
	String message = is.readLine();
	// TODO: I'm not sure if this is the best way to do this.
	// Maybe Read only first 5 bytes instead?
	if (message.startsWith(MOVED_RESPONSE)) {
		String[] movedInfo = parseTargetHostAndSlot(message);
		throw new JedisMovedDataException(message, new HostAndPort(movedInfo[1], Integer.valueOf(movedInfo[2])),
				Integer.valueOf(movedInfo[0]));
	} else if (message.startsWith(ASK_RESPONSE)) {
		String[] askInfo = parseTargetHostAndSlot(message);
		throw new JedisAskDataException(message, new HostAndPort(askInfo[1], Integer.valueOf(askInfo[2])),
				Integer.valueOf(askInfo[0]));
	} else if (message.startsWith(CLUSTERDOWN_RESPONSE)) {
		throw new JedisClusterException(message);
	} else if (message.startsWith(BUSY_RESPONSE)) {
		throw new JedisBusyException(message);
	} else if (message.startsWith(NOSCRIPT_RESPONSE)) {
		throw new JedisNoScriptException(message);
	}
	throw new JedisDataException(message);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:22,代码来源:Protocol.java


示例2: process

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static Object process(final RedisInputStream is) {

		final byte b = is.readByte();
		if (b == PLUS_BYTE) {
			return processStatusCodeReply(is);
		} else if (b == DOLLAR_BYTE) {
			return processBulkReply(is);
		} else if (b == ASTERISK_BYTE) {
			return processMultiBulkReply(is);
		} else if (b == COLON_BYTE) {
			return processInteger(is);
		} else if (b == MINUS_BYTE) {
			processError(is);
			return null;
		} else {
			throw new JedisConnectionException("Unknown reply: " + (char) b);
		}
	}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:19,代码来源:Protocol.java


示例3: processBulkReply

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static byte[] processBulkReply(final RedisInputStream is) {
	final int len = is.readIntCrLf();
	if (len == -1) {
		return null;
	}

	final byte[] read = new byte[len];
	int offset = 0;
	while (offset < len) {
		final int size = is.read(read, offset, (len - offset));
		if (size == -1)
			throw new JedisConnectionException("It seems like server has closed the connection.");
		offset += size;
	}

	// read 2 more bytes for the command delimiter
	is.readByte();
	is.readByte();

	return read;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:22,代码来源:Protocol.java


示例4: measureInputMulti

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static long measureInputMulti() throws Exception {
  long duration = 0;

  InputStream is = new ByteArrayInputStream(
      "*4\r\n$3\r\nfoo\r\n$13\r\nbarbarbarfooz\r\n$5\r\nHello\r\n$5\r\nWorld\r\n".getBytes());

  RedisInputStream in = new RedisInputStream(is);
  for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
    long start = System.nanoTime();
    Protocol.read(in);
    duration += (System.nanoTime() - start);
    in.reset();
  }

  return duration;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:17,代码来源:ProtocolBenchmark.java


示例5: connect

import redis.clients.util.RedisInputStream; //导入依赖的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


示例6: processError

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static void processError(final RedisInputStream is) {
  String message = is.readLine();
  // TODO: I'm not sure if this is the best way to do this.
  // Maybe Read only first 5 bytes instead?
  if (message.startsWith(MOVED_RESPONSE)) {
    String[] movedInfo = parseTargetHostAndSlot(message);
    throw new JedisMovedDataException(message, new HostAndPort(movedInfo[1],
        Integer.valueOf(movedInfo[2])), Integer.valueOf(movedInfo[0]));
  } else if (message.startsWith(ASK_RESPONSE)) {
    String[] askInfo = parseTargetHostAndSlot(message);
    throw new JedisAskDataException(message, new HostAndPort(askInfo[1],
        Integer.valueOf(askInfo[2])), Integer.valueOf(askInfo[0]));
  } else if (message.startsWith(CLUSTERDOWN_RESPONSE)) {
    throw new JedisClusterException(message);
  }
  throw new JedisDataException(message);
}
 
开发者ID:x7-framework,项目名称:x7,代码行数:18,代码来源:Protocol.java


示例7: process

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static Object process(final RedisInputStream is) {

    final byte b = is.readByte();
    if (b == PLUS_BYTE) {
      return processStatusCodeReply(is);
    } else if (b == DOLLAR_BYTE) {
      return processBulkReply(is);
    } else if (b == ASTERISK_BYTE) {
      return processMultiBulkReply(is);
    } else if (b == COLON_BYTE) {
      return processInteger(is);
    } else if (b == MINUS_BYTE) {
      processError(is);
      return null;
    } else {
      throw new JedisConnectionException("Unknown reply: " + (char) b);
    }
  }
 
开发者ID:x7-framework,项目名称:x7,代码行数:19,代码来源:Protocol.java


示例8: processBulkReply

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static byte[] processBulkReply(final RedisInputStream is) {
  final int len = is.readIntCrLf();
  if (len == -1) {
    return null;
  }

  final byte[] read = new byte[len];
  int offset = 0;
  while (offset < len) {
    final int size = is.read(read, offset, (len - offset));
    if (size == -1) throw new JedisConnectionException(
        "It seems like server has closed the connection.");
    offset += size;
  }

  // read 2 more bytes for the command delimiter
  is.readByte();
  is.readByte();

  return read;
}
 
开发者ID:x7-framework,项目名称:x7,代码行数:22,代码来源:Protocol.java


示例9: connect

import redis.clients.util.RedisInputStream; //导入依赖的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


示例10: process

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static Object process(final RedisInputStream is) {
try {
    byte b = is.readByte();
    if (b == MINUS_BYTE) {
	processError(is);
    } else if (b == ASTERISK_BYTE) {
	return processMultiBulkReply(is);
    } else if (b == COLON_BYTE) {
	return processInteger(is);
    } else if (b == DOLLAR_BYTE) {
	return processBulkReply(is);
    } else if (b == PLUS_BYTE) {
	return processStatusCodeReply(is);
    } else {
	throw new JedisConnectionException("Unknown reply: " + (char) b);
    }
} catch (IOException e) {
    throw new JedisConnectionException(e);
}
return null;
   }
 
开发者ID:wjw465150,项目名称:shiro-redis,代码行数:22,代码来源:Protocol.java


示例11: processBulkReply

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static byte[] processBulkReply(final RedisInputStream is) {
int len = Integer.parseInt(is.readLine());
if (len == -1) {
    return null;
}
byte[] read = new byte[len];
int offset = 0;
try {
    while (offset < len) {
	offset += is.read(read, offset, (len - offset));
    }
    // read 2 more bytes for the command delimiter
    is.readByte();
    is.readByte();
} catch (IOException e) {
    throw new JedisConnectionException(e);
}

return read;
   }
 
开发者ID:wjw465150,项目名称:shiro-redis,代码行数:21,代码来源:Protocol.java


示例12: processError

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
/**
 * 处理Redis集群重定向"请求错误"响应。
 *
 * @param is
 */
private static void processError(RedisInputStream is) {
	String message = is.readLine();
	// TODO: I'm not sure if this is the best way to do this.
	// Maybe Read only first 5 bytes instead?
	if (message.startsWith(MOVED_RESPONSE)) {
		String[] movedInfo = parseTargetHostAndSlot(message);
		throw new JedisMovedDataException(message, new HostAndPort(
				movedInfo[1], Integer.valueOf(movedInfo[2])),
				Integer.valueOf(movedInfo[0]));
	} else if (message.startsWith(ASK_RESPONSE)) {
		String[] askInfo = parseTargetHostAndSlot(message);
		throw new JedisAskDataException(message, new HostAndPort(
				askInfo[1], Integer.valueOf(askInfo[2])),
				Integer.valueOf(askInfo[0]));
	} else if (message.startsWith(CLUSTERDOWN_RESPONSE)) {
		throw new JedisClusterException(message);
	}
	throw new JedisDataException(message);
}
 
开发者ID:EdwardLee03,项目名称:jedis-sr,代码行数:25,代码来源:Protocol.java


示例13: process

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
/**
 * 处理Redis命令执行的响应信息。
 *
 * @param is
 * @return
 */
private static Object process(RedisInputStream is) {
	try {
		byte b = is.readByte();
		if (b == MINUS_BYTE) {
			processError(is);
		} else if (b == ASTERISK_BYTE) {
			return processMultiBulkReply(is);
		} else if (b == COLON_BYTE) {
			return processInteger(is);
		} else if (b == DOLLAR_BYTE) {
			return processBulkReply(is);
		} else if (b == PLUS_BYTE) {
			return processStatusCodeReply(is);
		} else {
			throw new JedisConnectionException("Unknown reply: " + (char) b);
		}
	} catch (IOException e) {
		// 抛出"Redis连接异常"
		throw new JedisConnectionException(e);
	}
	// 可能返回 NULL
	return null;
}
 
开发者ID:EdwardLee03,项目名称:jedis-sr,代码行数:30,代码来源:Protocol.java


示例14: processBulkReply

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static byte[] processBulkReply(RedisInputStream is) {
	int len = Integer.parseInt(is.readLine());
	if (len == -1) {
		return null;
	}
	byte[] read = new byte[len];
	
	int offset = 0;
	try {
		while (offset < len) {
			int size = is.read(read, offset, (len - offset));
			if (size == -1)
				throw new JedisConnectionException(
						"It seems like server has closed the connection.");
			offset += size;
		}
		// read 2 more bytes for the command delimiter (命令分隔符)
		is.readByte();
		is.readByte();
	} catch (IOException e) {
		throw new JedisConnectionException(e);
	}

	return read;
}
 
开发者ID:EdwardLee03,项目名称:jedis-sr,代码行数:26,代码来源:Protocol.java


示例15: processMultiBulkReply

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static List<Object> processMultiBulkReply(RedisInputStream is) {
	int num = Integer.parseInt(is.readLine());
	if (num == -1) {
		return null;
	}
	List<Object> ret = new ArrayList<Object>(num);
	for (int i = 0; i < num; i++) {
		try {
			ret.add(process(is)); // 递归地解析命令的响应内容
		} catch (JedisDataException e) {
			// Bug 怎么把异常返回的数据也添加到返回信息里去了???
			ret.add(e);
		}
	}
	return ret;
}
 
开发者ID:EdwardLee03,项目名称:jedis-sr,代码行数:17,代码来源:Protocol.java


示例16: readErrorLineIfPossible

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
public static String readErrorLineIfPossible(RedisInputStream is) {
	final byte b = is.readByte();
	// if buffer contains other type of response, just ignore.
	if (b != MINUS_BYTE) {
		return null;
	}
	return is.readLine();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:9,代码来源:Protocol.java


示例17: processMultiBulkReply

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static List<Object> processMultiBulkReply(final RedisInputStream is) {
	final int num = is.readIntCrLf();
	if (num == -1) {
		return null;
	}
	final List<Object> ret = new ArrayList<Object>(num);
	for (int i = 0; i < num; i++) {
		try {
			ret.add(process(is));
		} catch (JedisDataException e) {
			ret.add(e);
		}
	}
	return ret;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:16,代码来源:Protocol.java


示例18: measureInputStatus

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
private static long measureInputStatus() throws Exception {
  long duration = 0;

  InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes());

  RedisInputStream in = new RedisInputStream(is);
  for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
    long start = System.nanoTime();
    Protocol.read(in);
    duration += (System.nanoTime() - start);
    in.reset();
  }

  return duration;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:16,代码来源:ProtocolBenchmark.java


示例19: fragmentedBulkReply

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
@Test
public void fragmentedBulkReply() {
  FragmentedByteArrayInputStream fis = new FragmentedByteArrayInputStream(
      "$30\r\n012345678901234567890123456789\r\n".getBytes());
  byte[] response = (byte[]) Protocol.read(new RedisInputStream(fis));
  assertArrayEquals(SafeEncoder.encode("012345678901234567890123456789"), response);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:8,代码来源:ProtocolTest.java


示例20: multiBulkReply

import redis.clients.util.RedisInputStream; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void multiBulkReply() {
  InputStream is = new ByteArrayInputStream(
      "*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n".getBytes());
  List<byte[]> response = (List<byte[]>) Protocol.read(new RedisInputStream(is));
  List<byte[]> expected = new ArrayList<byte[]>();
  expected.add(SafeEncoder.encode("foo"));
  expected.add(SafeEncoder.encode("bar"));
  expected.add(SafeEncoder.encode("Hello"));
  expected.add(SafeEncoder.encode("World"));
  assertByteArrayListEquals(expected, response);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:14,代码来源:ProtocolTest.java



注:本文中的redis.clients.util.RedisInputStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java XUnoUrlResolver类代码示例发布时间:2022-05-22
下一篇:
Java MimeBodyPart类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap