java redis 删除指定前缀的key

public class Tests {
    public static void main(String[] args) {
        System.out.println("----------------Tests main-----------------");
        Jedis jedis = new Jedis("127.0.0.1", 6379);

        jedis.set("ws1", "1");
        jedis.set("ws2", "2");
        jedis.set("ws3", "3");

        Set<String> keys = jedis.keys("ws*");

        System.out.println(keys);

        for (String key : keys) {
            jedis.del(key);
        }

        System.out.println(jedis.keys("ws*"));

    }
}
结果如下:
----------------Tests main-----------------
[ws1, ws3, ws2]
[]

你可能感兴趣的:(Java)