Module: Redis::TimeSeries::Client

Included in:
Redis::TimeSeries
Defined in:
lib/redis/time_series/client.rb

Overview

The client module handles connection management for individual time series, and the parent Redis::TimeSeries class methods. You can enable or disable debugging, and set a default Redis client to use for time series objects.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/redis/time_series/client.rb', line 10

def self.extended(base)
  base.class_eval do
    attr_reader :redis

    private

    def cmd(name, *args)
      self.class.send :cmd_with_redis, redis, name, *args
    end
  end
end

Instance Method Details

#debugBoolean

Check debug status. Defaults to on with DEBUG=true environment variable.

Returns:

  • (Boolean)

    current debug status



24
25
26
# File 'lib/redis/time_series/client.rb', line 24

def debug
  @debug.nil? ? [true, 'true', 1].include?(ENV['DEBUG']) : @debug
end

#debug=(bool) ⇒ Boolean

Enable or disable debug output for time series commands. Enabling debug will print commands to STDOUT as they’re executed.

Examples:

[1] pry(main)> @ts1.get
=> #<Redis::TimeSeries::Sample:0x00007fc82e9de150 @time=2020-07-19 15:01:13 -0700, @value=0.56e2>
[2] pry(main)> Redis::TimeSeries.debug = true
=> true
[3] pry(main)> @ts1.get
DEBUG: TS.GET ts1
 => #<Redis::TimeSeries::Sample:0x00007fc82f11b7b0 @time=2020-07-19 15:01:13 -0700, @value=0.56e2>

Returns:

  • (Boolean)

    new debug status



41
42
43
# File 'lib/redis/time_series/client.rb', line 41

def debug=(bool)
  @debug = !!bool
end

#redisRedis

Returns the current Redis client. Defaults to Redis.new.

Returns:

  • (Redis)

    the current Redis client. Defaults to Redis.new



46
47
48
# File 'lib/redis/time_series/client.rb', line 46

def redis
  @redis ||= Redis.new
end

#redis=(client) ⇒ Redis

Set the default Redis client for time series objects. This may be useful if you already use a non-time-series Redis database, and want to use both at the same time.

Examples:

# config/initializers/redis_time_series.rb
Redis::TimeSeries.redis = Redis.new(url: 'redis://my-redis-server:6379/0')

Parameters:

  • client (Redis)

    a Redis client

Returns:



60
61
62
# File 'lib/redis/time_series/client.rb', line 60

def redis=(client)
  @redis = client
end