0

When I do

redis -h host -a password -p port HVALS myhash

command on redis, it will return all values of that hash, one per line. In my case that values are JSON formatted strings.

I want to store that return on shell variable and after that use in loop. That strings are separated with spaces by default.

I can treat all questions to avoid any problem to use this variable with loop structure, but I wonder if redis has some way to return a array of strings structure with redis command.

To give an idea about what I am looking for, think something similar or same result as this command:

redis -h host -a password -p port HVALS myhash | jq -s

In this case jq will work nice because it will recognize JSON objects and will create a array of arrays.

I want to know if is possible to get any array structure of values using only redis, and does not matter if final result is not a valid JSON (forget the fact my strings are JSON strings). And I want only use redis to do this. I can do at shell scripting side, but is not the question.

0

If command redis -h host -a password -p port HVALS myhash can return result as each entry separated by <space> then you can use arrays.

hash_array=($(redis -h host -a password -p port HVALS myhash))

and then you iterate with for loop

for item in "${hash_array[@]}"
do
echo "$item"
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.