redis命令的使用

1、在何处使用redis命令

在redis安装目录下的redis-cli.exe中使用命令

2、查看和设置redis密码

密码登录:auth "123"

查看密码:config get requirepass

设置密码:config set requirepass "123"

3、批量导入

a、生成redis命令文件,如下是生成set命令文件的方法:

public static void generateShell(String sourceFilePath, String shellFilePath) throws IOException {
    List<String> datas = Files.readAllLines(Paths.get(sourceFilePath));
    StringBuffer redisCommands = new StringBuffer();
    for (String data: datas) {
        if (StringUtils.isEmpty(data)) {
            continue;
        }
        data = data.replace("\"", "");// 防止添加的数据中包含双引号
        data = "SADD test \"" + data + "\"\r\n";
        redisCommands.append(data);
    }
    Files.write(Paths.get(shellFilePath), redisCommands.toString().getBytes());
}
上边方法关键点是“\r\n”。

b、执行redis的pipe命令

linux:cat redis_commands.txt  | redis-cli --pipe -h ip -p port -a password
windows:type redis_commands.txt  | redis-cli --pipe -h ip -p port -a password
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值