0
votes

I got a folder (I believe you call it a Set) in my Redis database named "g", where I store some keys.

KEYS *g:*

Returns

g: wasted
g: two
g: hours
g: with
g: this

First question: How can I make the query so I get the results below?

wasted
two
hours
with
this

"wasted","two","hours","with" and "this" are documents (I believe you call them keys?) with two columns and 100 rows inside. "Wasted" contains this:

 Hash Key      Hash Value 
 I             Myself
 Am            ToBe
 So            TooMuch
 Wasted        Wasted

Second question: How do I make a query to retrieve all keys and values?

I got a temp solution by replicating data. I created a folder, inserted just strings inside (I believe you call them hashes), and I just iterate over that folder/set and return each key one by one. But for production we would have to replicate 2TB of data, and that we cannot do.

1
Don't use "KEYS". Keys will iterate ALL the keys in your database, even those not starting with g:. As Itamar says, use SETS. - user827329

1 Answers

0
votes

WRT question 1: you should really learn about Redis' different data structures, but from the looks of it you're not using a Set but rather just setting keys with a common prefix. To use a Set, you'll need to call SADD, e.g.:

SADD g wasted two hours with this

Each of the "documents" is a member is the set, and calling SMEMBERS on it will return them.

WRT question 2: assuming you are asking how to get all the fields and their respective values from a Hash, use HGETALL.