Saving and retrieving an array of strings in Redis

I am looking for some examples of getting and setting string arrays, and I cannot find it or make it work.

The strings themselves are SecureRandom.hex values. Think of them as invitation codes. I want to create a key / value pair:

1) Key=> invite:code:88bb4bdfef Value=> userid

2) Key=> userid:invite:codes Value => 88bb4bdfef,73dbfac453,etc... (one entry for each of the previous sets)

I just get hung up on managing the values ​​in the second key / value pair.

UPDATE: Therefore, the task is that if I create an array and set it like this:

 foo=Array.new foo.push("abc") foo.push("def") 

at this moment foo looks like this: ["A", "DEF"]

So, I installed foo in redis to restore it:

 $redis.set(:foo,foo) bar=$redis.get(:foo) 

Now the panel looks like this: "[\" A \ "\" Protection \ "]"

+4
source share
1 answer

Here you need lists or sets, not simple keys. Here is an example of using the Redis function:

 $redis.sadd("userid:invite:codes", ["88bb4bdfef", "73dbfac453"]) $redis.smembers("userid:invite:codes") => ["88bb4bdfef", "73dbfac453"] 
+7
source

Source: https://habr.com/ru/post/1483657/


All Articles