import redis clients jedis Jedis import java util Iterator import java

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import redis.clients.jedis.Jedis;
import java.util.Iterator;
import java.util.Set;
enum Modif {
ins, del, exam;
}
public class AddKeyWord {
public static void main(String[] args){
Jedis jedis = new Jedis("localhost");
//jedis.sadd("filter", "word1");
//jedis.sadd("filter", "word2");
//jedis.srem("filter", "word1");
Modif modif = Modif.valueOf(args[0]);
switch (modif) {
case ins:
{
for(int i = 1; i < args.length; i++)
jedis.sadd("filter", args[i]);
break;
}
case del:
{
for(int i = 1; i < args.length; i++)
jedis.srem("filter", args[i]);
//jedis.sismember() проверка на принадлежность множества
break;
}
case exam:
{
Set<String> names=jedis.smembers("filter");
Iterator<String> it = names.iterator();
while (it.hasNext()) {
String s = it.next();
System.out.print(s + "\n");
}
break;
}
}
}
}