redis lpop 异常
这是一个只知其然,不知其所以然 的问题:
通过不同的方式使用 lpop ,返回的 值不同。求是什么原因。
我不清楚,都是同样的redis jar包,怎么返回值是这样不同的?
异常代码如下:
public class Redis {
private Jedis jedis;//非切片额客户端连接
private JedisPool jedisPool;//非切片连接池
private ShardedJedis shardedJedis;//切片额客户端连接
private ShardedJedisPool shardedJedisPool;//切片连接池
public Redis()
{
initialPool();
initialShardedPool();
shardedJedis = shardedJedisPool.getResource();
jedis = jedisPool.getResource();
}
/**
* 初始化非切片池
*/
private void initialPool()
{
// 池基本配置
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(20);
config.setMaxIdle(5);
config.setMaxWaitMillis(1000);
config.setTestOnBorrow(false);
jedisPool = new JedisPool(config,"127.0.0.1",6379);
}
/**
* 初始化切片池
*/
private void initialShardedPool()
{
// 池基本配置
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(20);
config.setMaxIdle(5);
config.setMaxWaitMillis(10001);
config.setTestOnBorrow(false);
// slave链接
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
shards.add(new JedisShardInfo("127.0.0.1", 6379, "master"));
// 构造池
shardedJedisPool = new ShardedJedisPool(config, shards);
}
public String ListOperate(String listName) {
String popVlue = shardedJedis.lpop(listName);
if(popVlue != null)
{
System.out.println("首元素 - " + listName + " : " + popVlue);
}
return popVlue;
}
}
(string -> json)
lpop 返回的 json 值 :
MessageBean{codeId='c634654fc7c1d79fb8a2b07e97c93186', codeName='XYCMS婚纱摄影网站源码', codeType='software', fastDFSId='group1/M00/00/00/CgoGMlpC8mqANqAJAGDOKEJgnpQ231.rar', source='null', codeVersion='vasp版', category='国产软件', fileSize='7.19M', author='null', timestamp=1514336860586}
找了好多,试了好多:
换成了如下的代码:
public class redisDemo {
private String host = "127.0.0.1";
private int port = 6379;
private int db = 4;
private String key = "dll_info_analyzing_task_list";
private Jedis jedis;
public void initRedis() {
jedis = new Jedis(host, port);
jedis.select(db);
}
public void closeRedis() {
jedis.quit();
jedis.close();
}
public String lpop(String key) {
String getvalue = jedis.lpop(key);
return getvalue;
}
public redisDemo()
{
initRedis();
}
protected void finalize() throws java.lang.Throwable {
closeRedis();
// 递归调用超类中的finalize方法
super.finalize();
System.out.println("对象已被释放");
}
}
(string -> json)
返回的 json 值:
{"codeId":"eaead8b2868f995a21f7b535a5238fee","codeVersion":"vasp版","codeType":"software","fastDFSId":"group1/M00/00/00/CgoGMlpC8peAUqGzAAS5uiCTXb8143.rar","fileSize":"0.3M","author":"null","codeName":"122411小型论坛源码","source":"null","category":"国产软件","timestamp":1514336918622}
redis可视化软件中看到的值:
{codeId:'e2bb1008f47e737e0c2adef2a75f52c4', codeName:'asp 冠龙科技企业网站管理系统', codeType:'software', fastDFSId:'group1/M00/00/00/CgoGMlpC8meAN1w2AFRXxlyNODU906.rar', source:'null', codeVersion:'v2016', category:'国产软件', fileSize:'6.80M', author:'null', timestamp:1514336860203}
我不清楚,都是同样的redis jar包,怎么返回值是这样不同的?