html tool

显示标签为“java”的博文。显示所有博文
显示标签为“java”的博文。显示所有博文

2020年10月14日星期三

概念-澄清- 垃圾回收机制

 垃圾回收机制

  • https://www.jianshu.com/p/5261a62e4d29

    垃圾回收回收的是无任何引用的对象占据的内存空间而不是对象本身。 换言之,垃圾回收只会负责释放那些对象占有的内存。对象是个抽象的词,包括引用和其占据的内存空间。当对象没有任何引用时其占据的内存空间随即被收回备用,此时对象也就被销毁。但不能说是回收对象,可以理解为一种文字游戏。

    判断是否是垃圾的算法

    -引用计数算法(Reference Counting Collector)[早期使用,现在多废弃,缺点:循环引用无法发现]

    -根搜索算法(Tracing Collector)[当前多数使用,从GC root对象出发,搜索引用链]

    回收算法

    -Tracing算法(Tracing Collector) 或 标记—清除算法[使用根算法, 防止环问题,新问题:效果不高,过多内存碎片]

    -Compacting算法(Compacting Collector) 或 标记—整理算法[先将所有对象移动到一端,清除端界以外内存,解决了标记-清除的问题,新问题: GC停止时间长,更新引用的地址]

    -Copying算法(Copying Collector)[两块内存分别使用,整理时复制存活到另一块中, 解决标记-整理算法的问题, 适合新生代(短周期的对象),问题:内存可用率下降一半]

    -Adaptive算法(Adaptive Collector)[在特定的情况下,一些垃圾收集算法会优于其它算法。基于Adaptive算法的垃圾收集器就是监控当前堆的使用情况,并将选择适当算法的垃圾收集器] [popexizhi: 哈哈,太厉害了,看来要进化到更高级了]

2020年10月10日星期六

概念-分清 接口与抽象类是否相同

 接口与抽象类是否相同

  • [popexizhi] (参考: https://www.zhihu.com/question/20149818)

    why引入 interface

    java本身不允许多继承,  interface 的引入,是为解决这个问题

    抽象类的设计目的,是代码复用。当不同的类具有某些相同的行为(记为行为集合A),且其中一部分行为的实现方式一致时(A的非真子集,记为B),可以让这些类都派生于一个抽象类。在这个抽象类中实现了B,避免让所有的子类来实现B,这就达到了代码复用的目的。而A减B的部分,留给各个子类自己实现。正是因为A-B在这里没有实现,所以抽象类不允许实例化出来(否则当调用到A-B时,无法执行)

     

    - 接口的设计目的,是对类的行为进行约束(更准确的说是一种“有”约束,因为接口不能规定类不可以有什么行为),也就是提供一种机制,可以强制要求不同的类具有相同的行为。它只约束了行为的有无,但不对如何实现行为进行限制。

    abstruct class 是已经实现的方法,也可以有方法,如下的解释说道很清楚

     - 抽象类的设计目的,是代码复用。当不同的类具有某些相同的行为(记为行为集合A),且其中一部分行为的实现方式一致时(A的非真子集,记为B),可以让这些类都派生于一个抽象类。在这个抽象类中实现了B,避免让所有的子类来实现B,这就达到了代码复用的目的。而A减B的部分,留给各个子类自己实现。正是因为A-B在这里没有实现,所以抽象类不允许实例化出来(否则当调用到A-B时,无法执行)


2019年11月19日星期二

java中位移运算符优先级低于+-


堆算法中的beginindex 和 li/ri确定中用到位移运算没有加(),unittest一直无法通过
go了一下 java中位移运算符优先级低于+-

https://blog.csdn.net/zll0927/article/details/12277543

口诀:括单算关位逻条赋

括号(1级): ()  [ ](数组取下标) .(取成员变量)
单目(2级)(从右向左) ! +(正)-(负)~(按位取反) ++ --
算术(3-5级) * / %---->>>> + ----->>>><< >> >>>
关系(6-7级) < <= > >= instanceof---->>>> == !=
位(8-10级)(特殊的单目) & ---->>>>^ ---->>>> |
逻辑(11-12级) && ---->>>> ||
条件(13级) ? :
赋值(14级)(从右向左) = += -+ *= /= %= &= |= ^= ~= <<= >>= >>>=
————————————————
版权声明:本文为CSDN博主「zll0927」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zll0927/article/details/12277543

2019年3月20日星期三

jmeter: Uncaught Exception java.lang.OutOfMemoryError: Java heap space



问题:

jmeter 导出html时提示:
Uncaught Exception java.lang.OutOfMemoryError: Java heap space

解决:

http://www.51testing.com/html/14/209114-817579.html

linux环境,修改jmeter.sh

下面添加如下配置:
java $JVM_ARGS -Xms1G -Xmx5G -XX:MaxPermSize=512m -Dapple.laf.useScreenMenuBar=true -jar `dirname $0`/ApacheJMeter.jar "$@"
一般根据实际情况修改-Xmx5G,由小改到大

windows环境,修改jmeter.bat

set HEAP=-Xms256m -Xmx256m
set NEW=-XX:NewSize=128m -XX:MaxNewSize=128m
改为:
set HEAP=-Xms256m -Xmx1024m
set NEW=-XX:NewSize=128m -XX:MaxNewSize=512m
【popexizhi: windows,pope单独修改了Xmx2G 就ok了】

2018年1月7日星期日

转:Protocol http not supported or disabled in libcurl


http://blog.csdn.net/ocan/article/details/9282245

又一次血的教训:Protocol http not supported or disabled in libcurl


上传图片报错:http not supported or disabled in libcurl
找运维查配置
调试问题
怎么都找不到问题出在何处,最后,,,最后,,,,擦得嘞,是开发人员在配置的url前多了个空格。。。。。。
去掉http前面空格解决了问题。

2017年12月5日星期二

[?]jmeter 命令行运行https 如何配置密钥呢?

问题: GUI 测试时要在ssl manage 中添加密钥
【参考:
  1. The final step is to finally point JMeter at the keystore we want to use. Click Options -> SSL Manager and select the mystore.keystore keystore that we created and press Enter.
  2. https://developer.ibm.com/mainframe/docs/how-to-test-your-apis/how-to-configure-jmeter-to-use-client-side-ssl/
  3. 找到工具栏“选项”-〉SSL管理器。打开bin目录下的ApacheJMeterTemporaryRootCA.crt即可。
  4. http://www.jianshu.com/p/efe03b4d02a3

,但是看了xml文件没有这个项目啊?
在命令行运行时, 不配置也可以运行成功,好奇怪,这个不用配置吗?

2017年11月16日星期四

jMeter html生成图表的时间粒度问题

参考:http://blog.csdn.net/hwhua1986/article/details/78348391

[问题: jmeter 生成的html报告中默认的统计时间是一分钟统计一次,如何修改为秒钟呢?]

原文中与自己有相同问题如下:
3、坑3:我用了很久发现表格里面的图表都是按1min的平均值统计的,这样颗粒度太大了,图表不是按秒钟显示散点图,对实际的压测结果偏差太大。如图点击率和响应时间。跟使用GUI界面压测结果完全不同。

修改方式是 reportgenerator.properties 中的


# Defines the overall granularity for over time graphs
# Granularity must be higher than 1000 (1second) otherwise Throughput graphs will be incorrect
# see Bug 60149
#jmeter.reportgenerator.overall_granularity=60000 #安装后默认是1分钟的位置
jmeter.reportgenerator.overall_granularity=1000 #设置的最小值为1000毫秒


自己修改后的报告如下:

PS:
查看了一下html报告的源码,本来是很想不行就自己改数据间隔的,发现数据储存位置为
$reportdir\content\js\graph.js 中
定义的responseTimesOverTimeInfos 之类的变量中存储的data节点数据,如下图:

2017年11月14日星期二

jmeter出现java.lang.OutOfMemoryError: Java heap space

参考: http://blog.csdn.net/yue530tomtom/article/details/76529619

原文如下:
若某些JVM选项不支持,可以编辑jmeter shell脚本进行修改。环境变量JVM_ARGS用来覆盖JVM设置
JVM_ARGS=”-Xms1024m -Xmx1024m” jmeter -t test.jmx [etc.]
但自己用3.3的agent 设置是jmeter-server 的启动,在启动脚本添加后查看进程没有变还是有问题,最后查看jmeter的java启动命令,原来如下,修改为使用$JVM_ARGS就ok了



86 # This is the base heap size -- you may increase or decrease it to fit your
 87 # system's memory availability:
 88 #HEAP="-Xms512m -Xmx512m" #[popexizhi:这是默认的配置,下面是自己修改的]
 89 HEAP=$JVM_ARGS
 90  
 91 #VERBOSE_GC="-verbose:gc -Xloggc:gc_jmeter_%p.log -XX:+PrintGCDetails -XX:+PrintGCCause -XX:+PrintTenuringDistribution -XX:+PrintHe    apAtGC -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDateStamps"
 92  
 93 # Finally, some tracing to help in case things go astray:
 94 GC_ALGO="-XX:+UseG1GC -XX:MaxGCPauseMillis=250 -XX:G1ReservePercent=20"
 95  
 96  
 97 # Always dump on OOM (does not cost anything unless triggered)
 98 DUMP="-XX:+HeapDumpOnOutOfMemoryError"
 99 SYSTEM_PROPS="-Djava.security.egd=file:/dev/urandom"
100 SERVER="-server"
101  
102 ARGS="$SERVER $DUMP $HEAP $VERBOSE_GC $GC_ALGO $SYSTEM_PROPS"
103  
104 java $ARGS $JVM_ARGS $JMETER_OPTS -jar "$PRGDIR/ApacheJMeter.jar" "$@"
~                                                                             

jmeter结果分析图

生成方式参考:
https://www.cnblogs.com/Akubi/p/5946897.html?utm_source=itdadao&utm_medium=referral
【popexizhi:
吐槽一下,用惯了loadrunner的结果分析对jmeter的简陋图表一致表示比较愤怒,都临门一脚了苦于没有作好,不过JMeter3.0还真是做了,还不错


生成报告

a. 在压力测试结束时报告
  • 基本命令格式:
    jmeter -n -t -l -e -o
  • 样例:
    jmeter -n -t E:\apache-jmeter-3.0\script\test.jmx -l LogFile -e -o ./report
b. 使用已有的压力测试CSV日志文件生成报告
  • 基本命令格式:
    jmeter -g -o
  • 样例:
    jmeter -g E:\apache-jmeter-3.0\bin\LogFile -o ./report
两个样例都会在\apache-jmeter-3.0\bin\report目录下产生对应的文件(夹),



用浏览器打开index.html文件,即可查看各种图形化报告:


其默认提供的度量维度包括:
  1. APDEX(Application Performance Index)指数
  2. 聚合报告
    • 类似于UI上的Aggregate Report
  3. Errors报告
    • 展示不同错误类型的数量以及百分比
  4. 响应时间变化曲线
    • 展示平均响应时间随时间变化情况
    • 类似于JMeter Plugins在UI上的jp@gc - Response Times Over Time
  5. 数据吞吐量时间曲线
    • 展示每秒数据吞吐量随时间变化的情况
    • 类似于JMeter Plugins在UI上的jp@gc - Bytes Throughput Over Time
  6. Latency time变化曲线
    • 展示Latency time随时间变化的情况
    • 类似于JMeter Plugins在UI上的jp@gc - Response Latencies Over Time
  7. 每秒点击数曲线
    • 类似于JMeter Plugins在UI上的jp@gc - Hits per Second
  8. HTTP状态码时间分布曲线
    • 展示响应状态码随时间的分布情况
    • 类似于JMeter Plugins在UI上的jp@gc - Response Codes per Second
  9. 事务吞吐量时间曲线(TPS)
    • 展示每秒处理的事务数随时间变化情况
    • 类似于JMeter Plugins在UI上的jp@gc - Transactions per Second
  10. 平均响应时间与每秒请求数的关系图
    • 展示平均响应时间与每秒请求数(可以理解为QPS)的关系
  11. Latency time与每秒请求数的关系图
    • 展示Latency time与每秒请求数的关系
  12. 响应时间百分位图
    • 响应时间的百分位分布图
  13. 活动线程数变化曲线
    • 展示测试过程中活动线程数随时间变化情况
  14. 平均响应时间与线程数的关系图
    • 展示平均响应时间与线程数的关系
    • 类似于JMeter Plugins在UI上的jp@gc - Response Times vs Threads
  15. 柱状响应时间分布图
    • 展示落在各个平均响应时间区间的请求数情况
- Latency time = 接收到响应的第一个字节的时间点 - 请求开始发送的时间点
from just before sending the request to just after the first response has been received
-- Apache JMeter Glossary
- 响应时间(JMeter术语中的Elapsed time) = 接收完所有响应内容的时间点 - 请求开始发送的时间点

from just before sending the request to just after the last response has been received
-- Apache JMeter Glossary

转:jmeter中BeanShell Sampler引用java代码的3种方式---java,class

http://blog.csdn.net/kaluman/article/details/73119662

//导入java文件
public String test()
{
 log.info("********************************************1");
 source("G:\\jmeter_test\\Demo.java");
 log.info("********************************************2");
 test11 ts = new test11();
 log.info("********************************************3");
 int res = ts.test();
 //int res = ts.x();
 vars.put("resA",res.toString());
 log.info(vars.get("resA"));
 return "success";  
}
test();

//导入class文件
addClassPath("D:\\");
import com.AddMethod;//AddMethod是class文件的文件名,放到D盘比较深的一个目录里
int addm = new AddMethod().add(6,9);
vars.put("num",addm.toString());
vars.put("name","kaku");
log.info("test");
return "success";
return num;

二、验证方式
当不确定写的代码或者引用的java文件是否正确时,可以通过下面的步骤,去验证是否正确。
1、在测试计划上,用户定义的变量这里,添加一个常量
2、在BeanShell Sampler上下方各添加一个Debug Sampler,并在最后加上查看结果数的监听器,如上图;
3、然后分别把上面讲到的方式去进行试验,看最后一个Debug Sampler的响应数据是否跟着java代码设置的而变化了,如下



转:JMeter与BeanShell的化学反应


http://dev.dafan.info/detail/218176?p=31-57


BeanShell的内置对象

对象名存在元素功能
logBeanShell Sampler 
BeanShell PreProcessor 
BeanShell PostProcessor 
BeanShell Assertion 
BeanShell Listener
日志信息输出
LabelBeanShell Sampler样例
FileNameBeanShell Sampler文件名
ParametersBeanShell Sampler参数
bsh.argsBeanShell SamplerBeanShell脚本
SampleResultBeanShell Sampler 
BeanShell Assertion 
BeanShell Listener
样例结果
ResponseCodeBeanShell Sampler 
BeanShell Assertion
返回的状态码
ResponseMessageBeanShell Sampler 
BeanShell Assertion
返回信息
IsSucessBeanShell Sampler是否成功
ctxBeanShell Sampler 
BeanShell PreProcessor 
BeanShell PostProcessor 
BeanShell Assertion 
BeanShell Listener
JMeter的上下文
varsBeanShell Sampler,BeanShell PreProcessor 
BeanShell PostProcessor 
BeanShell Assertion 
BeanShell Listener
变量操作
propsBeanShell Sampler 
BeanShell PreProcessor 
BeanShell PostProcessor 
BeanShell Assertion 
BeanShell Listener
JMeter属性
prevBeanShell PreProcessor 
BeanShell PostProcessor 
BeanShell Listener
样例的前置结果读取
samplerBeanShell PreProcessor 
BeanShell PostProcessor
当前样例
ResponseBeanShell Assertion返回的对象,读-写
FailureBeanShell Assertion是否失败
FailureMessageBeanShell Assertion失败信息
ResponseDataBeanShell Assertion返回数据体,字节形式
ResponseHeaderBeanShell Assertion返回信息头
RequestHeaderBeanShell Assertion请求信息头
SampleLabelBeanShell Assertion样例名称
SampleDataBeanShell Assertion发送至服务器的数据
SampleEventBeanShell Listener读取当前样例的事件

2017年11月7日星期二

windows TCP连接


[问题]
System.out: can not listen to:java.net.BindException: Address already in use: connect Notify:
解决: http://blog.chinaunix.net/uid-90129-id-132845.html

 短时间内new socket操作过多
  而socket.close()操作并不能立即释放绑定的端口
  而是把端口设置为TIME_WAIT状态
  过段时间(默认240s)才释放(用netstat -na可以看到)
  最后系统资源耗尽
  (windows上是耗尽了pool of ephemeral ports 这段区间在1024-5000之间)
 Socket FAQ:
  Remember that TCP guarantees all data transmitted will be delivered,
if at all possible. When you close a socket, the server goes into a
TIME_WAIT state, just to be really really sure that all the data has
gone through. When a socket is closed, both sides agree by sending
messages to each other that they will send no more data. This, it
seemed to me was good enough, and after the handshaking is done, the
socket should be closed. The problem is two-fold. First, there is no
way to be sure that the last ack was communicated successfully.
Second, there may be "wandering duplicates" left on the net that must
be dealt with if they are delivered.

Andrew Gierth (andrew@erlenstar.demon.co.uk) helped to explain the
closing sequence in the following usenet posting:

Assume that a connection is in ESTABLISHED state, and the client is
about to do an orderly release. The client's sequence no. is Sc, and
the server's is Ss. Client Server
====== ======
ESTABLISHED ESTABLISHED
(client closes)
ESTABLISHED ESTABLISHED

【popexizhi:
用loadrunner 测试nginx max socket connect 个数时,agent端出现的错误,看了是windows的文件句柄限制,但是没有找到修改设置的位置。???改linux 做agent去了

2017年11月3日星期五

转:java zookeeper client Demo


http://blog.csdn.net/gaohuanjie/article/details/37736939

package com.ghj.packageoftest;  
  
import org.apache.zookeeper.CreateMode;  
import org.apache.zookeeper.WatchedEvent;  
import org.apache.zookeeper.Watcher;  
import org.apache.zookeeper.ZooDefs.Ids;  
import org.apache.zookeeper.ZooKeeper;  
  
public class ZooKeeperClient {  
  
    public static void main(String[] args) throws Exception{  
        Watcher watcher = new Watcher(){  
            // 监控所有被触发的事件  
            public void process(WatchedEvent event) {   
                System.out.println("触发了" + event.getType() + "事件!");   
            }  
        };  
  
        ZooKeeper zooKeeper = new ZooKeeper("127.0.0.1:2181", 5000, watcher);//第一个参数:ZooKeeper服务器的连接地址,如果ZooKeeper是集群模式或伪集群模式(即ZooKeeper服务器有多个),那么每个连接地址之间使用英文逗号间隔,单个连接地址的语法格式为“主机IP:ZooKeeper服务器端口号”;  
                                                                             //第二个参数:session超时时长(单位:毫秒)  
                                                                             //第三个参数:用于监控目录节点数据变化和子目录状态变化的Watcher对象  
        zooKeeper.create("/RootNode", "RootNodeData".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);//创建一个节点名为“/RootNode”的目录节点  
        System.out.println("“/RootNode”节点状态:" + zooKeeper.exists("/RootNode",true));//判断指定目录节点是否存在  
        System.out.println("“RootNode”节点上数据:"+new String(zooKeeper.getData("/RootNode", false, null)));//获取“RootNode”节点上的数据  
        zooKeeper.create("/RootNode/ChildNode1", "ChildNode1Data".getBytes(), Ids.OPEN_ACL_UNSAFE,CreateMode.PERSISTENT);//在“RootNode”节点下创建一个名为“ChildNode1”的子目录节点  
        zooKeeper.create("/RootNode/ChildNode2", "ChildNode2Data".getBytes(), Ids.OPEN_ACL_UNSAFE,CreateMode.PERSISTENT);//在“RootNode”节点下创建一个和“ChildNode1”同级的名为“ChildNode2”的子目录节点  
        System.out.println("目录节点“RootNode”下的所有子目录节点有:"+zooKeeper.getChildren("/RootNode",true)); //取出目录节点“RootNode”下的所有子目录节点  
        zooKeeper.setData("/RootNode/ChildNode2","NewChildNode2Data".getBytes(),-1);//修改名为“ChildNode2”的目录节点数据  
  
        zooKeeper.delete("/RootNode/ChildNode1", -1);//删除“/RootNode/ChildNode1”目录节点  
        System.out.println("“/RootNode/ChildNode1”节点状态:" + zooKeeper.exists("/RootNode/ChildNode1", false));//判断“/RootNode/ChildNode1”目录节点是否存在  
        zooKeeper.delete("/RootNode/ChildNode2", -1);//删除“/RootNode/ChildNode2”目录节点  
        zooKeeper.delete("/RootNode", -1);//删除“/RootNode”目录节点  
        zooKeeper.close(); //关闭与ZooKeeper的连接  
    }  
}  


写的很详细的注释,不多解释了。
Mvn的依赖


    org.apache.zookeeper
    zookeeper
    3.4.10
    pom

[popexizhi:
很奇怪的问题,    pom 添加后Eclipse本地的mvn install无法下载依赖,去掉就ok了,好奇怪,这个是原文提供的意思是什么呢?
]


2017年11月2日星期四

转:使用java内置的观察者模式

http://www.cnblogs.com/java-my-life/archive/2012/05/16/2502279.html

怎样使用JAVA对观察者模式的支持

  这里给出一个非常简单的例子,说明怎样使用JAVA所提供的对观察者模式的支持。在这个例子中,被观察对象叫做Watched;而观察者对象叫做Watcher。Watched对象继承自java.util.Observable类;而Watcher对象实现了java.util.Observer接口。另外有一个Test类扮演客户端角色。

  源代码

  被观察者Watched类源代码
复制代码
public class Watched extends Observable{
    
    private String data = "";
    
    public String getData() {
        return data;
    }

    public void setData(String data) {
        
        if(!this.data.equals(data)){
            this.data = data;
            setChanged(); //[popexizhi: 被观察者通知其他观察者可以更新数据的触发点]
        }
        notifyObservers();
    }
    
    
}
复制代码

  观察者类源代码
复制代码
public class Watcher implements Observer{
    
    public Watcher(Observable o){
        o.addObserver(this);
    }
    
    @Override
    public void update(Observable o, Object arg) {
        
        System.out.println("状态发生改变:" + ((Watched)o).getData());
    }

}
复制代码
  测试类源代码
复制代码
public class Test {

    public static void main(String[] args) {
        
        //创建被观察者对象
        Watched watched = new Watched();
        //创建观察者对象,并将被观察者对象登记
        Observer watcher = new Watcher(watched);
        //给被观察者状态赋值
        watched.setData("start");
        watched.setData("run");
        watched.setData("stop");

    }

}
复制代码
  Test对象首先创建了Watched和Watcher对象。在创建Watcher对象时,将Watched对象作为参数传入;然后Test对象调用Watched对象的setData()方法,触发Watched对象的内部状态变化;Watched对象进而通知实现登记过的Watcher对象,也就是调用它的update()方法。

转:java redis Demo

https://www.tutorialspoint.com/redis/redis_java.htm

import redis.clients.jedis.Jedis; 

public class RedisJava { 
   public static void main(String[] args) { 
      //Connecting to Redis server on localhost 
      Jedis jedis = new Jedis("localhost"); 
      System.out.println("Connection to server sucessfully"); 
      //check whether server is running or not 
      System.out.println("Server is running: "+jedis.ping()); 
   } 
} 

[popexizhi:
mvn pom.xml 依赖如下:
	
		redis.clients
		jedis
		2.8.1
	
可用版本参考:https://mvnrepository.com/artifact/redis.clients/jedis
]

________________________________________________________________________________________


-----------------------------------------------------
[popexizhi:1. redis 本地配置文件使用支持0.0.0.0的监听,默认启动使用的是127.0.0.12. redis-cli查看命令中 list 类型支持python的-1索引方式eg:LRANGE hi 0 -1
]
-----------------------------------------------------
其他类型数据参见: http://www.baeldung.com/jedis-java-redis-client-library
5.1. Strings
Strings are the most basic kind of Redis value, useful for when you need to persist simple key-value data types:
1
2
jedis.set("events/city/rome", "32,15,223,828");
String cachedResponse = jedis.get("events/city/rome");
The variable cachedResponse will hold the value 32,15,223,828. Coupled with expiration support, discussed later, it can work as a lightning fast and simple to use cache layer for HTTP requests received at your web application and other caching requirements.

5.2. Lists

Redis Lists are simply lists of strings, sorted by insertion order and make it an ideal tool to implement, for instance, message queues:
1
2
3
4
jedis.lpush("queue#tasks", "firstTask");
jedis.lpush("queue#tasks", "secondTask");
 
String task = jedis.rpop("queue#tasks");
The variable task will hold the value firstTask. Remember that you can serialize any object and persist it as a string, so messages in the queue can carry more complex data when required.

5.3. Sets

Redis Sets are an unordered collection of Strings that come in handy when you want to exclude repeated members:
1
2
3
4
5
6
jedis.sadd("nicknames", "nickname#1");
jedis.sadd("nicknames", "nickname#2");
jedis.sadd("nicknames", "nickname#1");
 
Set nicknames = jedis.smembers("nicknames");
boolean exists = jedis.sismember("nicknames", "nickname#1");
The Java Set nicknames will have a size of 2, the second addition of nickname#1 was ignored. Also, the existsvariable will have a value of true, the method sismember enables you to quickly check for the existence of a particular member.

5.4. Hashes

Redis Hashes are mapping between String fields and String values:
1
2
3
4
5
6
7
jedis.hset("user#1", "name", "Peter");
jedis.hset("user#1", "job", "politician");
         
String name = jedis.hget("user#1", "name");
         
Map fields = jedis.hgetAll("user#1");
String job = fields.get("job");
As you can see, hashes are a very convenient data type when you want to access object’s properties individually since you do not need to retrieve the whole object.