Sha256: 8858d7fcd285b7a9c98d9643b90d7eea9592d2ef835785dc6afe09008c338c17

Contents?: true

Size: 700 Bytes

Versions: 19

Compression:

Stored size: 700 Bytes

Contents

# frozen_string_literal: true

class RedisClient
  module PIDCache
    if !Process.respond_to?(:fork) # JRuby or TruffleRuby
      @pid = Process.pid
      singleton_class.attr_reader(:pid)
    elsif Process.respond_to?(:_fork) # Ruby 3.1+
      class << self
        attr_reader :pid

        def update!
          @pid = Process.pid
        end
      end
      update!

      module CoreExt
        def _fork
          child_pid = super
          PIDCache.update! if child_pid == 0
          child_pid
        end
      end
      Process.singleton_class.prepend(CoreExt)
    else # Ruby 3.0 or older
      class << self
        def pid
          Process.pid
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
redis-client-0.23.2 lib/redis_client/pid_cache.rb
redis-client-0.23.1 lib/redis_client/pid_cache.rb
redis-client-0.23.0 lib/redis_client/pid_cache.rb
redis-client-0.22.1 lib/redis_client/pid_cache.rb
redis-client-0.22.0 lib/redis_client/pid_cache.rb
redis-client-0.21.1 lib/redis_client/pid_cache.rb
redis-client-0.21.0 lib/redis_client/pid_cache.rb
redis-client-0.20.0 lib/redis_client/pid_cache.rb
redis-client-0.19.1 lib/redis_client/pid_cache.rb
redis-client-0.19.0 lib/redis_client/pid_cache.rb
redis-client-0.18.0 lib/redis_client/pid_cache.rb
redis-client-0.17.1 lib/redis_client/pid_cache.rb
redis-client-0.17.0 lib/redis_client/pid_cache.rb
redis-client-0.16.0 lib/redis_client/pid_cache.rb
redis-client-0.15.0 lib/redis_client/pid_cache.rb
redis-client-0.14.1 lib/redis_client/pid_cache.rb
redis-client-0.14.0 lib/redis_client/pid_cache.rb
redis-client-0.13.0 lib/redis_client/pid_cache.rb
redis-client-0.12.2 lib/redis_client/pid_cache.rb