首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >如何使用Jedis操作Redis消息队列

如何使用Jedis操作Redis消息队列

作者头像
用户1154259
发布2018-01-17 16:42:55
发布2018-01-17 16:42:55
1.2K0
举报

资源链接

Jedis的jar包 Commons-io的jar包

使用方法

代码样例如下,使用前,注意打开redis的server程序。

代码样例

代码语言:javascript
复制
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);
        }
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015-10-10 ,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • 资源链接
  • 使用方法
  • 代码样例
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档