Shell 在redis中加载文件时,值中插入了一行新行,如何避免这种情况
我正在尝试使用以下命令在redis中上载文件:Shell 在redis中加载文件时,值中插入了一行新行,如何避免这种情况,shell,redis,redis-cli,Shell,Redis,Redis Cli,我正在尝试使用以下命令在redis中上载文件: redis-cli -p <Port> -h <Host> -n <DB> -x set <key> < /tmp/file.json 因为您的文件包含换行符,所以这就是存储在Redis中的内容 在将文件内容设置为Redis之前,需要从文件中删除换行符。根据您的操作系统,方法可能会有所不同。这里有一个关于这个的问题:终于实现了- cat /tmp/up.json | redis-cli -n
redis-cli -p <Port> -h <Host> -n <DB> -x set <key> < /tmp/file.json
因为您的文件包含换行符,所以这就是存储在Redis中的内容
在将文件内容设置为Redis之前,需要从文件中删除换行符。根据您的操作系统,方法可能会有所不同。这里有一个关于这个的问题:终于实现了-
cat /tmp/up.json | redis-cli -n 20 --pipe
和up.json内容
set 'PACKAGES_CONFIG' '{"checkOfferFieldPrices":true,"showPrescInfoScreen":true,"showAddOnsScreen":true,"offerText":"1 + 1 with Lenskart Gold","bannerConfig":{"isVisible":true,"primaryText":"Hi %s, You are a GOLD Member!","secondaryText":"You are eligible for Buy 1 Get 1 offer on this order!"},"isExpandedByDefault":true,"isPreSelected":true,"displayBogoTabs": true, "defaultSelectedTabId": "buy2","tabConfig":[{"id":"buy1","title":"Buy 1","subtitle":"No Offer","enabled":true},{"id":"buy2","title":"Buy 2","subtitle":"Buy 1 Get 1 Free","enabled":true}]}'
tr-d'\n'/tmp/file.json | redis cli…
文件中没有新行,我检查了很多次。
set 'PACKAGES_CONFIG' '{"checkOfferFieldPrices":true,"showPrescInfoScreen":true,"showAddOnsScreen":true,"offerText":"1 + 1 with Lenskart Gold","bannerConfig":{"isVisible":true,"primaryText":"Hi %s, You are a GOLD Member!","secondaryText":"You are eligible for Buy 1 Get 1 offer on this order!"},"isExpandedByDefault":true,"isPreSelected":true,"displayBogoTabs": true, "defaultSelectedTabId": "buy2","tabConfig":[{"id":"buy1","title":"Buy 1","subtitle":"No Offer","enabled":true},{"id":"buy2","title":"Buy 2","subtitle":"Buy 1 Get 1 Free","enabled":true}]}'