I have just installed redis' last version on Ubuntu 18.04.3. I have tried out writing values directly with redis-cli
.
127.0.0.1:6379> set myket somevalue
I am now trying to delete all values from Jedis:
Jedis jedis = new Jedis("localhost", 6379);
Set<String> names=jedis.keys("NAME:*");
System.out.println("There are " + names.size() + " keys to delete");
Iterator<String> it = names.iterator();
while (it.hasNext()) {
String s = it.next();
jedis.del(s);
System.out.println(s + " has been deleted");
}
However, it always says that there are 0 keys right now. When I query it from redis-cli
directly, it is still there. How can I delete the keys from Jedis?
Your key name is myket
and your pattern is NAME:*
. The pattern NAME:*
doesn't match myket
. That's why you're finding 0 matching keys.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.