问题
I have a Rails app, and I want to use Azure Redis cache. So far as I got information from internet, I have created a Redis cache on Azure and I have installed Redis gem and I configured in following in redis.rb
$redis = Redis.new(:host => 'xxxxx.redis.cache.windows.net', :port => 6380, :db => 10, :password => "xxxxxxxxxxxxxxxxxxxxxxx", :use_ssl => true)
and after this I don't know how to map it with my database and how to use it.
回答1:
Based on my understanding, it sounds like you want to know how to use Azure Redis Cache via Ruby redis client redis-rb. According to your code, it seems that you had known how to install the redis client library for Ruby and get the connection information from Azure portal, but the code is incorrect.
Here is my sample code for using Ruby to connect Azure Redis Cache.
- Installing
redis-rb
viagem install redis
. My code as below.
# Import the redis library for Ruby require "redis" # Create a redis client instance for connecting Azure Redis Cache # At here, for enabling SSL, set the `:ssl` symbol with the # symbol value `:true`, see https://github.com/redis/redis-rb#ssltls-support redis = Redis.new( :host => '<azure redis cache name>.redis.cache.windows.net', :port => 6380, :db => <the db index you selected like 10>, :password => "<access key>", :ssl => :true) # Then, set key `foo` with value `bar` and return `OK` status = redis.set('foo', 'bar') puts status # => OK # Get the value of key `foo` foo = redis.get('foo') puts foo # => bar
More commands, please see Redis Offical page for Commands, but some commands can not be used on Azure Redis Cache, please see Redis commands not supported in Azure Redis Cache.
Hope it helps. Any concern, please feel free to let me know.
来源:https://stackoverflow.com/questions/41761958/how-to-setup-azure-redis-cache-with-rails