Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 112 lines (79 sloc) 2.162 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
# encoding: UTF-8

require File.expand_path("./helper", File.dirname(__FILE__))
require File.expand_path("./redis_mock", File.dirname(__FILE__))

include RedisMock::Helper

setup do
  init Redis.new(OPTIONS)
end

test "INFO" do |r|
  %w(last_save_time redis_version total_connections_received connected_clients total_commands_processed connected_slaves uptime_in_seconds used_memory uptime_in_days changes_since_last_save).each do |x|
    assert r.info.keys.include?(x)
  end
end

test "INFO COMMANDSTATS" do |r|
  # Only available on Redis >= 2.9.0
  next if version(r) < 209000

  r.config(:resetstat)
  r.ping

  result = r.info(:commandstats)
  assert "1" == result["ping"]["calls"]
end

test "MONITOR (Redis < 2.5.0)" do |r|
  next unless version(r) < 205000

  log = []

  wire = Wire.new do
    Redis.new(OPTIONS).monitor do |line|
      log << line
      break if log.size == 3
    end
  end

  Wire.pass while log.empty? # Faster than sleep

  r.set "foo", "s1"

  wire.join

  assert log[-1][%q{(db 15) "set" "foo" "s1"}]
end

test "MONITOR (Redis >= 2.5.0)" do |r|
  next unless version(r) >= 205000

  log = []

  wire = Wire.new do
    Redis.new(OPTIONS).monitor do |line|
      log << line
      break if line =~ /set/
    end
  end

  Wire.pass while log.empty? # Faster than sleep

  r.set "foo", "s1"

  wire.join

  assert log[-1] =~ /\b15\b.* "set" "foo" "s1"/
end

test "MONITOR returns value for break" do |r|
  result = r.monitor do |line|
    break line
  end

  assert result == "OK"
end

test "ECHO" do |r|
  assert "foo bar baz\n" == r.echo("foo bar baz\n")
end

test "DEBUG" do |r|
  r.set "foo", "s1"

  assert r.debug(:object, "foo").kind_of?(String)
end

test "OBJECT" do |r|
  r.lpush "list", "value"

  assert r.object(:refcount, "list") == 1
  assert r.object(:encoding, "list") == "ziplist"
  assert r.object(:idletime, "list").kind_of?(Fixnum)
end

test "SYNC" do |r|
  replies = {:sync => lambda { "+OK" }}

  redis_mock(replies) do
    redis = Redis.new(OPTIONS.merge(:port => MOCK_PORT))

    assert "OK" == redis.sync
  end
end

test "SLOWLOG" do |r|
  r.slowlog(:reset)
  result = r.slowlog(:len)
  assert result == 0
end
Something went wrong with that request. Please try again.