JedisDataException: ERR unknown command 'SENTINEL'

报错信息如下:


2015-1-30 20:06:15 redis.clients.jedis.JedisSentinelPool initSentinels
信息: Trying to find master from available Sentinels...
Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.uet.common.cache.RedisTest.main(RedisTest.java:7)
Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'SENTINEL'
	at redis.clients.jedis.Protocol.processError(Protocol.java:115)
	at redis.clients.jedis.Protocol.process(Protocol.java:133)
	at redis.clients.jedis.Protocol.read(Protocol.java:202)
	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:285)
	at redis.clients.jedis.Connection.getRawObjectMultiBulkReply(Connection.java:230)
	at redis.clients.jedis.Connection.getObjectMultiBulkReply(Connection.java:236)
	at redis.clients.jedis.Jedis.sentinelGetMasterAddrByName(Jedis.java:3051)
	at redis.clients.jedis.JedisSentinelPool.initSentinels(JedisSentinelPool.java:133)
	at redis.clients.jedis.JedisSentinelPool.<init>(JedisSentinelPool.java:74)
	at redis.clients.jedis.JedisSentinelPool.<init>(JedisSentinelPool.java:36)
	at com.uet.common.cache.JedisSentinelEngin.<clinit>(JedisSentinelEngin.java:35)
	... 1 more
代码:


package com.uet.common.cache;

import java.util.HashSet;
import java.util.ResourceBundle;
import java.util.Set;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;

public class JedisSentinelEngin {
	// private static final JedisPool pool;
	private static final JedisSentinelPool pool;
	private static final String REDIS_COUNT = "redis.server.count";
	static {
		ResourceBundle bundle = ResourceBundle.getBundle("redis");
		if (bundle == null) {
			throw new IllegalArgumentException("[redis.properties] is not found!");
		}
		/*JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxTotal(Integer.valueOf(bundle.getString("redis.pool.maxTotal")));
		config.setMaxIdle(Integer.valueOf(bundle.getString("redis.pool.maxIdle")));
		config.setMaxWaitMillis(Long.valueOf(bundle.getString("redis.pool.maxWait")));
		config.setTestOnBorrow(Boolean.valueOf(bundle.getString("redis.pool.testOnBorrow")));
		config.setTestOnReturn(Boolean.valueOf(bundle.getString("redis.pool.testOnReturn")));*/
		
		int count = Integer.valueOf(bundle.getString(REDIS_COUNT));
		Set<String> sentinels = new HashSet<String>();
		for (int i = 0; i < count; i++) {
			String ip = bundle.getString(String.format("redis.%d.ip", i));
			int port = Integer.valueOf(bundle.getString(String.format("redis.%d.port", i)));
			HostAndPort info = new HostAndPort(ip, port);
			sentinels.add(info.toString());
		}
		pool = new JedisSentinelPool("mymaster", sentinels); 
	}

	public static JedisSentinelPool getPool() {
		return pool;
	}
}



草木全
分享到:
1

貌似是sentinel没有启动。

执行下面的命令:


src/redis-sentinel sentinel.conf --sentinel


也有可能是你客户端连接错了:

JedisSentinelPool 要连接服务端的IP及sentinel产品的端口。


共1条评论

优秀到卓越 正解啊 「3年前」
2
共 1 条   当前1/1页

© 2014 究问社区 copyRight 豫ICP备13003319号-1