Map<String, JedisPool> map = jc.getClusterNodes(); for (Map.Entry<String, JedisPool> e : map.entrySet()) { System.out.println(e.getKey()); System.out.println("==================="); }
}
运行时报错:
1 2 3 4 5 6
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool at redis.clients.util.Pool.getResource(Pool.java:53) at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226) at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot(JedisSlotBasedConnectionHandler.java:66) ... ...
因为在之前创建创建集群时使用的IP是127.0.0.1,当返回(error) MOVED 10439 127.0.0.1:6381时,系统尝试连接本地的端口,然后连不上失败了
public static void main(String[] args) { List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(); JedisShardInfo si = new JedisShardInfo("192.168.1.213", 6380); shards.add(si); si = new JedisShardInfo("192.168.1.213", 6381); shards.add(si); si = new JedisShardInfo("192.168.1.213", 6382); shards.add(si);
public static void main(String[] args) { List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(); JedisShardInfo si = new JedisShardInfo("192.168.1.213", 6380); shards.add(si); si = new JedisShardInfo("192.168.1.213", 6381); shards.add(si); si = new JedisShardInfo("192.168.1.213", 6382); shards.add(si);
// 池连接 JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); ShardedJedisPool pool = new ShardedJedisPool(jedisPoolConfig, shards);
/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- redis (LoadError) from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require' from ./redis-trib.rb:25:in `<main>'
curl -L get.rvm.io | bash -s stable % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 194 100 194 0 0 308 0 --:--:-- --:--:-- --:--:-- 307 100 24361 100 24361 0 0 12772 0 0:00:01 0:00:01 --:--:-- 89410 Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc gpg: 已创建目录‘/root/.gnupg’ gpg: 新的配置文件‘/root/.gnupg/gpg.conf’已建立 gpg: 警告:在‘/root/.gnupg/gpg.conf’里的选项于此次运行期间未被使用 gpg: 钥匙环‘/root/.gnupg/pubring.gpg’已建立 gpg: 于 2017年09月11日 星期一 04时59分21秒 CST 创建的签名,使用 RSA,钥匙号 BF04FF17 gpg: 无法检查签名:没有公钥 Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.3.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:
NOTE: GPG version 2.1.17 have a bug which cause failures during fetching keys from remote server. Please downgrade or upgrade to newer version (if available) or use the second method described above.
Installing RVM to /usr/local/rvm/ Installation of RVM in /usr/local/rvm/ is almost complete:
* First you need to add all users that will be using rvm to 'rvm' group, and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.
* To start using RVM you need to run `source /etc/profile.d/rvm.sh` in all your open shell windows, in rare cases you need to reopen all shell windows.
设置下环境变量,在查看下rvm版本
1 2 3
[root@wwh214 redis]# source /etc/profile.d/rvm.sh [root@wwh214 redis]# rvm --version rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
使用RVM升级Ruby版本 查看rvm库中已知的ruby版本
1 2 3 4 5 6 7 8 9 10 11 12 13
$ rvm list known # MRI Rubies [ruby-]1.8.6[-p420] [ruby-]1.8.7[-head] # security released on head [ruby-]1.9.1[-p431] [ruby-]1.9.2[-p330] [ruby-]1.9.3[-p551] [ruby-]2.0.0[-p648] [ruby-]2.1[.10] [ruby-]2.2[.7] [ruby-]2.3[.4] [ruby-]2.4[.1] ruby-head
安装2.4版本的ruby
1 2 3 4 5 6 7 8 9 10 11
$ rvm install 2.4.1 Searching for binary rubies, this might take some time. Found remote file https://rvm_io.global.ssl.fastly.net/binaries/centos/7/x86_64/ruby-2.4.1.tar.bz2 Checking requirements for centos. Installing requirements for centos. Installing required packages: libffi-devel, readline-devel, sqlite-devel, libyaml-devel............ Requirements installation successful. ruby-2.4.1 - #configure ruby-2.4.1 - #download ... ...
在查看一下
1 2 3 4 5 6 7 8 9 10 11 12
[root@wwh214 redis]# rvm list
rvm rubies
=* ruby-2.4.1 [ x86_64 ]
# => - current # =* - current && default # * - default
public static void main(String[] args) { ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigB.class); // now both beans A and B will be available... A a = ctx.getBean(A.class); B b = ctx.getBean(B.class); }
public class MainApp { public static void main(String[] args) { ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
// Let us raise a start event. context.start(); HelloWorld obj = (HelloWorld) context.getBean("helloWorld"); obj.getMessage();
<bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld"> <property name = "message" value = "Hello World!"/> </bean>
<bean id = "cStartEventHandler" class = "com.tutorialspoint.CStartEventHandler"/> <bean id = "cStopEventHandler" class = "com.tutorialspoint.CStopEventHandler"/>
</beans>
程序运行结果
1 2 3
ContextStartedEvent Received Your Message : Hello World! ContextStoppedEvent Received
public class CustomEvent extends ApplicationEvent{ public CustomEvent(Object source) { super(source); } public String toString(){ return "My Custom Event"; } }
public class CustomEventHandler implements ApplicationListener<CustomEvent> { public void onApplicationEvent(CustomEvent event) { System.out.println(event.toString()); } }
<bean id = "customEventHandler" class = "com.tutorialspoint.CustomEventHandler"/> <bean id = "customEventPublisher" class = "com.tutorialspoint.CustomEventPublisher"/>
<!-- A simple bean definition --> <bean id = "..." class = "..."> <!-- collaborators and configuration for this bean go here --> </bean>
<!-- A bean definition with lazy init set on --> <bean id = "..." class = "..." lazy-init = "true"> <!-- collaborators and configuration for this bean go here --> </bean>
<!-- A bean definition with initialization method --> <bean id = "..." class = "..." init-method = "..."> <!-- collaborators and configuration for this bean go here --> </bean>
<!-- A bean definition with destruction method --> <bean id = "..." class = "..." destroy-method = "..."> <!-- collaborators and configuration for this bean go here --> </bean>
public class InitHelloWorld implements BeanPostProcessor { public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { System.out.println("BeforeInitialization : " + beanName); return bean; // you can return any other object as well } public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { System.out.println("AfterInitialization : " + beanName); return bean; // you can return any other object as well } }
<bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld"> <property name = "message1" value = "Hello World!"/> <property name = "message2" value = "Hello Second World!"/> </bean>
<bean id =" helloIndia" class = "com.tutorialspoint.HelloIndia" parent = "helloWorld"> <property name = "message1" value = "Hello India!"/> <property name = "message3" value = "Namaste India!"/> </bean> </beans>
<bean id = "beanTeamplate" abstract = "true"> <property name = "message1" value = "Hello World!"/> <property name = "message2" value = "Hello Second World!"/> <property name = "message3" value = "Namaste India!"/> </bean>
<bean id = "helloIndia" class = "com.tutorialspoint.HelloIndia" parent = "beanTeamplate"> <property name = "message1" value = "Hello India!"/> <property name = "message3" value = "Namaste India!"/> </bean> </beans>
<!-- Definition for textEditor bean using inner bean --> <bean id = "textEditor" class = "com.tutorialspoint.TextEditor"> <property name = "spellChecker"> <bean id = "spellChecker" class = "com.tutorialspoint.SpellChecker"/> </property> </bean>
<!-- Definition for javaCollection --> <bean id = "javaCollection" class = "com.tutorialspoint.JavaCollection"> <!-- results in a setAddressList(java.util.List) call --> <property name = "addressList"> <list> <value>INDIA</value> <value>Pakistan</value> <value>USA</value> <value>USA</value> </list> </property>
<!-- results in a setAddressSet(java.util.Set) call --> <property name = "addressSet"> <set> <value>INDIA</value> <value>Pakistan</value> <value>USA</value> <value>USA</value> </set> </property>
<!-- results in a setAddressMap(java.util.Map) call --> <property name = "addressMap"> <map> <entry key = "1" value = "INDIA"/> <entry key = "2" value = "Pakistan"/> <entry key = "3" value = "USA"/> <entry key = "4" value = "USA"/> </map> </property> <!-- results in a setAddressProp(java.util.Properties) call --> <property name = "addressProp"> <props> <prop key = "one">INDIA</prop> <prop key = "one">INDIA</prop> <prop key = "two">Pakistan</prop> <prop key = "three">USA</prop> <prop key = "four">USA</prop> </props> </property> </bean>