0

I am trying to upload a file in redis using command:

redis-cli -p <Port> -h <Host> -n <DB> -x set <key> < /tmp/file.json 

The problem is : in redis value -

It is storing a \n at the end of line and I don't want this.

"{\"items\":{\"38749\":{\"buyone\":0,\"buytwo\":10},\"38712\":{\"buyone\":0,\"buytwo\":10},\"112775\":{\"buyone\":0,\"buytwo\":10},\"38721\":{\"buyone\":0,\"buytwo\":10},\"38720\":{\"buyone\":0,\"buytwo\":10},\"38714\":{\"buyone\":0,\"buytwo\":10},\"38726\":{\"buyone\":0,\"buytwo\":10},\"38733\":{\"buyone\":0,\"buytwo\":10},\"38729\":{\"buyone\":0,\"buytwo\":10},\"113708\":{\"buyone\":0,\"buytwo\":10},\"38731\":{\"buyone\":0,\"buytwo\":10},\"38745\":{\"buyone\":0,\"buytwo\":10},\"38732\":{\"buyone\":0,\"buytwo\":10},\"100074\":{\"buyone\":0,\"buytwo\":10},\"38730\":{\"buyone\":0,\"buytwo\":10},\"38719\":{\"buyone\":0,\"buytwo\":10},\"38723\":{\"buyone\":0,\"buytwo\":10},\"38755\":{\"buyone\":0,\"buytwo\":10},\"38760\":{\"buyone\":0,\"buytwo\":10}}}\n"
Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
Pankaj Kumar Katiyar
  • 1,474
  • 1
  • 20
  • 36

2 Answers2

0

Since your file contains newlines, that's what gets stored in Redis.

You'll need to strip the newlines from your file before setting its contents to Redis. Depending on your OS, the method may vary. Here's a question about this: How do I remove newlines from a text file?

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
0

Finally got this working -

cat /tmp/up.json | redis-cli -n 20 --pipe

and up.json contents

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}]}'
Pankaj Kumar Katiyar
  • 1,474
  • 1
  • 20
  • 36