This worked, but I had to explicitly define the Redis connection variable in global scope with the $. See below. Vielen dank for the suggestion, Magnus!
filter {
# Test filter that just uses the Ruby filter to add a field to every record
ruby {
init => 'require "redis";
require "time";
$rc = Redis.new(path: "/tmp/redis.sock", port: 6379, db: 3)'
code => 'start_time = Time.now
begin
event.set("redis_status", "OK")
event.set("redis_val", $rc.hget("redis_test", "first_val"))
rescue
event.set("redis_status", "Cannot connect")
end
end_time = Time.now
event.set("redis_elapsed", end_time - start_time)'
}
}