java的redis队列怎么使用_如何使用Jedis操作Redis消息队列

资源链接

[Jedis的jar包] 1

[Commons-io的jar包] 2

使用方法

代码样例如下,使用前,注意打开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);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值