Quantcast
Channel: Active questions tagged redis+ruby-on-rails - Stack Overflow
Viewing all articles
Browse latest Browse all 873

How to return all values with matched key from Redis store

$
0
0

Working an learning some Redis and I am running into an issue that I can't figure out why it is not working.

It is my understanding from some posts and documentation I read that I can store data with similar keys like this

redis.set("fruit:1", "apple")# OKredis.set("fruit:2", "banana")# OK

and it is my understanding I should be able to get all fruit like this

redis.get("fruit:*")

But I am missing something because this keep returning null and I cannot figure out what I need to do to return something like

=> apple, banana

I was able to figure out, using scan (suggested in answer below as well) how to return all matching fruit keys, but what I need is to search for all matching fruit keys, and then return the values for them.

@redis.scan_each(match: "fruit:*") do |fruit|  Rails.logger.debug('even run?')  fruits << fruitend=> fruit:1, fruit:2 # What I need though is apple, banana

What solved it (at least so far) is using mGet

@redis.scan_each(match: "fruit:*") do |fruit|  Rails.logger.debug('even run?')  fruits << @redis.mGet(fruit)end

Viewing all articles
Browse latest Browse all 873

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>