【问题标题】:Deleting Multiple Keys in Redis在 Redis 中删除多个键
【发布时间】:2020-10-13 20:07:02
【问题描述】:

在我的 redis 数据库中,我正在尝试删除一系列以以下开头的键:

EPOCH_vgsOwnedVehs_

我尝试了以下方法:

redis-cli -h 127.0.0.1 -p myport -a mypassword --scan --pattern EPOCH_vgsOwnedVehs_* | xargs redis-cli unlink

redis-cli -h 127.0.0.1 -p myport -a mypassword --scan --pattern EPOCH_vgsOwnedVehs_* | xargs redis-cli -h 127.0.0.1 -p myport -a mypassword unlink

但是,我收到以下错误消息:

'xargs' is not recognized as an internal or external command, operable program or batch file.

谁能帮助解释为什么 xargs 在这种情况下不起作用?我看到上面提到的相同语法在这里被多次提及,并且似乎对其他人有用......

编辑:我忘了提到,当我在管道之前运行该行的前半部分时,它确实返回了所有符合条件的键。

【问题讨论】:

    标签: redis xargs


    【解决方案1】:

    以下应该做的工作; (添加了一个示例打印输出)

    redis-cli -h 127.0.0.1 -p 6379 -a mypass --scan --pattern EPOCH_vgsOwnedVehs_* | xargs redis-cli -h 127.0.0.1 -p 6379 -a mypass unlink

    127.0.0.1:6379> config set requirepass mypass
    OK
    127.0.0.1:6379> auth mypass
    OK
    127.0.0.1:6379> set EPOCH_vgsOwnedVehs_a a
    OK
    127.0.0.1:6379> set EPOCH_vgsOwnedVehs_b a
    OK
    127.0.0.1:6379> set EPOCH_vgsOwnedVehs_c a
    OK
    127.0.0.1:6379> set EPOCH_vgsOwnedVehs_d a
    OK
    127.0.0.1:6379>
    
    redis-cli -h 127.0.0.1 -p 6379 -a mypass --scan --pattern EPOCH_vgsOwnedVehs_* | xargs redis-cli -h 127.0.0.1 -p 6379 -a mypass unlink
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    (integer) 4
    
    
    127.0.0.1:6379> auth mypass
    OK
    127.0.0.1:6379> exists EPOCH_vgsOwnedVehs_a
    (integer) 0
    

    【讨论】:

    • 感谢您的回答。我已经尝试过了,得到了完全相同的结果:'xargs' is not recognized as an internal or external command, operable program or batch file.
    • @BaroN 你用windows吗?
    • 是的。 Windows 服务器 2012 r2
    • @BaroN xargs 在 Windows 上不可用 - 我认为这就是您收到错误的原因。您可能需要安装一些工具才能使用xargs,例如github.com/bmatzelle/gow/wiki
    • 谢谢,这让我更进一步,但现在我收到错误消息(error) ERR unknown command 'unlink'
    【解决方案2】:

    xargs 是一个常见的 Linux 实用程序,您看到的消息表明您使用的是 Windows。你有几个选择可以让这个工作 - 你可以找到 xargs 的 Windows 替代品,使用 Cygwin,使用 Powershell 等。

    【讨论】:

    • 感谢您的解释。我尝试从 redis 文件夹中运行 powershell,但出现此错误:redis-cli : The term 'redis-cli' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + redis-cli -h 127.0.0.1 -p 6381 -a mypass --scan --pattern EPOCH_vgsOwnedVehs_* + ~~~~~~~~~ + CategoryInfo : ObjectNotFound: (redis-cli:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
    • Powershell 需要与 Linux shell 类似的符号 - 所以如果你想从当前文件夹运行某些东西,你需要在它前面加上 .\ ,例如.\redis-cli
    • 谢谢,这也让我更进一步,但是,与上面相同的问题,我收到以下错误消息(error) ERR unknown command 'unlink'
    猜你喜欢
    • 2011-08-29
    • 2018-04-09
    • 1970-01-01
    • 2022-01-12
    • 2017-04-02
    • 2018-03-10
    • 2015-09-10
    • 1970-01-01
    • 2019-12-31
    相关资源
    最近更新 更多