Execute Redis commands in bulk with scripts

Source: Internet
Author: User

Recently in the maintenance of a cache with the Redis project, encountered a product needs to eliminate the need to clean up the user's data, because each time to clear a lot of user data, each manual deletion is more cumbersome, and finally adopted a batch script to execute the command of the Purge

The command to be executed begins with a command line in a text file, similar to this one, and named Command.txt


Zrem incr:cjapp1271:day:20150805 1237806859
zrem incr:cjapp1271:day:20150805 723652156
: day:20150805 841597167
zrem incr:cjapp1271:day:20150805 1048187667
Zrem 1091051751
zrem incr:cjapp1271:day:20150805 1264716668
zrem
incr:cjapp1271:day:20150805 Zrem incr:cjapp1271:day:20150805 1264782549
zrem incr:cjapp1271:day:20150805 1264852503 zrem incr:cjapp1271
:d ay:20150805 1264853578
zrem incr:cjapp1271:day:20150805 1264854083

2. Then write the script, named del.sh

#!/bin/sh
host=$1
port=$2
password=$3
cat command.txt |/usr/local/redis/bin/redis-cli-h $host-P $ Port-a $password--pipe

3. Then perform sh des.sh localhost 6379 on the machine where Redis is located, so that all the commands in Command.txt can be executed quickly

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.