I want to run a bash script from node.js to remove all session keys from redis every time the server restarts.
I have read somewhere that Keys
shouldn't be used to delete multiple keys with a pattern because it would subject the server to security risks like DoS. Would this bash script a safer way to delete keys? Does xargs -L 1000
mean in each loop it will delete 1000 keys? Am I understanding it correctly?
#!/bin/bash
redis-cli --scan --pattern "SESSION:*" | xargs -L 1000 redis-cli del
I took the comman line from HERE.