How can I remotely inspect the data in my RedisClo

2019-04-01 01:17发布

问题:

I'm using Heroku to host a simple Ruby on Rails test app to learn how to use Redis. I'm using RedisCloud as my Redis servis provider. Locally, I can inspect my Redis DBs using the Redis CLI, but how can I inspect the data in the RedisCloud DBs that my Heroku app is using?

RedisCloud provides a dashboard that shows stats, but not the actual data. Also, I've tried using the Redis Desktop Manager software, but it has too many bugs to allow me to remotely connect to my RedisCloud DBs.

回答1:

Step by step:

1 - Check your Heroku config, in order to find out the REDIS URL.

heroku config

You should see an entrance that look like this:

REDISCLOUD_URL:              redis://rediscloud:foobarfoobarfoobar@a-redis-address:18888

2 - Connect to your remote Redis DB using redis-cli:

redis-cli -h a-redis-address -p 18888 -a foobarfoobarfoobar

You should be able to query your Redis DB now.



回答2:

Since you are using Rails you can also connect to the Rails console like this:

$ heroku run console

Once connected, you will have an initialized redis connection based on your configuration (eg. you have $redis = Redis.new(url: ENV["REDISCLOUD_URL"]) in your config/initializers/redis.rb):

irb(main):001:0> $redis
=> #<Redis client v3.2.1 for redis://domain.com/0>

Alternatively, you can make a new one:

irb(main):002:0> $redis2 = Redis.new(url: 'redis://domain.com')
irb(main):003:0> $redis2
=> #<Redis client v3.2.1 for redis://domain.com/0>