Ruby redisに接続して画像をキーに保存する

環境
Redis 7.0.4
Ubuntu 22.10

操作方法
1.ライブラリ「redis-objects」をインストールします
gem install redis-objects

2.redisに接続して、画像をキー「imagekey」の値として保存します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
require 'redis'
require 'redis/objects'
redis = Redis.new(
:host => 'localhost',
:port => 6379,
:db => 0
)
path = "test.png"
File.open(path, 'rb') do |file|
redis.set('imagekey', file.read)
end
require 'redis' require 'redis/objects' redis = Redis.new( :host => 'localhost', :port => 6379, :db => 0 ) path = "test.png" File.open(path, 'rb') do |file| redis.set('imagekey', file.read) end
require 'redis'
require 'redis/objects'

redis = Redis.new(
  :host => 'localhost',
  :port => 6379,
  :db => 0
)

path = "test.png"

File.open(path, 'rb') do |file|  
  redis.set('imagekey', file.read)
end

 

Redis

Posted by arkgame