How to Use Jedis to operate Redis message queues
Resources
Jedis jar package
Commons-io jar package
Usage
The sample code is as follows. before using it, open the redis server program.
Sample Code
Package RedisExample; import redis. clients. jedis. jedis; public class TestRedis {public static void main (String [] args) {Jedis redis = new Jedis ("localhost"); // SimpleExample (redis ); // ListExample (redis, 20000); PublishExample (redis, 20000);} // Add the public static void SimpleExample (Jedis redis) {redis. set ("key1", "I am value 1"); String ss = redis. get ("key1"); System. out. println (ss);} // queue add information p Ublic static void ListExample (Jedis redis, int number) {String messageStr = ""; int count = 0; while (count ++ <number) {messageStr = "this is" + count + "message! "; Redis. rpush ("logstash-test-list", messageStr); System. out. println (messageStr) ;}// publish and subscribe to public static void PublishExample (Jedis redis, int number) {String messageStr = ""; int count = 0; while (count ++ <number) {messageStr = "this is" + count + "message! "; Redis. publish (" logstash-test-list ", messageStr); System. out. println (messageStr );}}}
Download the Jedis jar package and the Commons-io jar package:
Download the Helper home Resource Station:
------------------------------------------ Split line ------------------------------------------
Free in http://linux.bkjia.com/
The username and password are both www.bkjia.com
The specific download directory is in/July 6, 2016,/July 23, March,/How to Use Jedis to operate Redis message queues/
For the download method, see
------------------------------------------ Split line ------------------------------------------
You may also like the following articles about Redis. For details, refer:
Install and test Redis in Ubuntu 14.04
Basic configuration of Redis master-slave Replication
Redis cluster details
Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis
Redis series-installation, deployment, and maintenance
Install Redis in CentOS 6.3
Learning notes on Redis installation and deployment
Redis. conf
Redis details: click here
Redis: click here
This article permanently updates the link address: