DEV: uses Discourse.redis instead of $redis

This commit is contained in:
Joffrey JAFFEUX 2019-12-03 10:45:32 +01:00
parent 05d4338a12
commit 6540d8b957
3 changed files with 6 additions and 6 deletions

View File

@ -7,7 +7,7 @@ class DiscourseChat::PublicController < ApplicationController
params.require(:secret)
redis_key = "chat_integration:transcript:#{params[:secret]}"
content = $redis.get(redis_key)
content = Discourse.redis.get(redis_key)
if content
render json: { content: content }

View File

@ -192,7 +192,7 @@ module DiscourseChat
def self.save_transcript(transcript)
secret = SecureRandom.hex
redis_key = "chat_integration:transcript:#{secret}"
$redis.setex(redis_key, 3600, transcript)
Discourse.redis.setex(redis_key, 3600, transcript)
secret
end

View File

@ -311,13 +311,13 @@ RSpec.describe DiscourseChat::Manager do
it 'saves a transcript to redis' do
key = DiscourseChat::Helper.save_transcript("Some content here")
expect($redis.get("chat_integration:transcript:#{key}")).to eq("Some content here")
expect(Discourse.redis.get("chat_integration:transcript:#{key}")).to eq("Some content here")
ttl = $redis.pttl("chat_integration:transcript:#{key}")
ttl = Discourse.redis.pttl("chat_integration:transcript:#{key}")
# Slight hack since freeze_time doens't work on redis
expect($redis.pttl("chat_integration:transcript:#{key}")).to be <= (3601 * 1000)
expect($redis.pttl("chat_integration:transcript:#{key}")).to be >= (3599 * 1000)
expect(Discourse.redis.pttl("chat_integration:transcript:#{key}")).to be <= (3601 * 1000)
expect(Discourse.redis.pttl("chat_integration:transcript:#{key}")).to be >= (3599 * 1000)
end
end