lib/cacheflow/redis.rb in cacheflow-0.2.1 vs lib/cacheflow/redis.rb in cacheflow-0.3.0
- old
+ new
@@ -1,7 +1,29 @@
module Cacheflow
module Redis
+ # redis 5 / redis-client
+ module ClientNotifications
+ def call(command, redis_config)
+ payload = {
+ commands: [command]
+ }
+ ActiveSupport::Notifications.instrument("query.redis", payload) do
+ super
+ end
+ end
+
+ def call_pipelined(commands, redis_config)
+ payload = {
+ commands: commands
+ }
+ ActiveSupport::Notifications.instrument("query.redis", payload) do
+ super
+ end
+ end
+ end
+
+ # redis 4
module Notifications
def logging(commands)
payload = {
commands: commands
}
@@ -26,7 +48,14 @@
end
end
end
end
-Redis::Client.prepend(Cacheflow::Redis::Notifications)
+if defined?(RedisClient)
+ RedisClient.register(Cacheflow::Redis::ClientNotifications)
+end
+
+if Redis::VERSION.to_i < 5
+ Redis::Client.prepend(Cacheflow::Redis::Notifications)
+end
+
Cacheflow::Redis::Instrumenter.attach_to(:redis)