redis lpop 异常

x_xx_xxx_xxxx x_xx_xxx_xxxx 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这是一个只知其然,不知其所以然 的问题:

通过不同的方式使用 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包,怎么返回值是这样不同的?
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
x_xx_xxx_xxxx
Java SE 62,620 成员 307,251 内容