如何使用Jedis操作Redis消息队列
资源
Jedis的jar包
Commons-io的jar包
使用方法
代码样例如下,使用前,注意打开redis的server程序。
代码样例
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);
}
//简单添加信息
public static void SimpleExample(Jedis redis){
redis.set("key1", "I am value 1");
String ss = redis.get("key1");
System.out.println(ss);
}
//队列添加信息
public 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);
}
}
//发布订阅
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);
}
}
}Jedis的jar包 与 Commons-io的jar包 下载:
安科网资源站下载:
------------------------------------------分割线------------------------------------------
具体下载目录在 /2016年资料/3月/23日/如何使用Jedis操作Redis消息队列/
------------------------------------------分割线------------------------------------------
下面关于Redis的文章您也可能喜欢,不妨参考下:
Redis 的详细介绍:请点这里
Redis 的下载地址:请点这里
相关推荐
txj 2020-08-17
亦碎流年 2020-06-18
middleware0 2020-06-13
anglehearts 2020-04-03
camhan 2020-05-09
枫叶上的雨露 2020-05-04
zhangtianshun 2020-05-03
博了个客 2020-04-29
sunzxh 2020-04-22
八角塘塘主 2020-04-09
GavinZhera 2020-04-08
郭宇 2020-02-22
Cheetahcubs 2020-02-12
middleware0 2020-02-11
wangxiaoxue 2020-01-23
guweiyuthinker 2020-01-20
MLXY 2020-01-21