Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 103 lines (68 sloc) 1.735 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
# 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

load "./test/lint/value_types.rb"

test "DEL" do |r|
  r.set "foo", "s1"
  r.set "bar", "s2"
  r.set "baz", "s3"

  assert ["bar", "baz", "foo"] == r.keys("*").sort

  assert 1 == r.del("foo")

  assert ["bar", "baz"] == r.keys("*").sort

  assert 2 == r.del("bar", "baz")

  assert [] == r.keys("*").sort
end

test "DEL with array argument" do |r|
  r.set "foo", "s1"
  r.set "bar", "s2"
  r.set "baz", "s3"

  assert ["bar", "baz", "foo"] == r.keys("*").sort

  assert 1 == r.del(["foo"])

  assert ["bar", "baz"] == r.keys("*").sort

  assert 2 == r.del(["bar", "baz"])

  assert [] == r.keys("*").sort
end

test "RANDOMKEY" do |r|
  assert r.randomkey.to_s.empty?

  r.set("foo", "s1")

  assert "foo" == r.randomkey

  r.set("bar", "s2")

  4.times do
    assert ["foo", "bar"].include?(r.randomkey)
  end
end

test "RENAME" do |r|
  r.set("foo", "s1")
  r.rename "foo", "bar"

  assert "s1" == r.get("bar")
  assert nil == r.get("foo")
end

test "RENAMENX" do |r|
  r.set("foo", "s1")
  r.set("bar", "s2")

  assert false == r.renamenx("foo", "bar")

  assert "s1" == r.get("foo")
  assert "s2" == r.get("bar")
end

test "DBSIZE" do |r|
  assert 0 == r.dbsize

  r.set("foo", "s1")

  assert 1 == r.dbsize
end

test "FLUSHDB" do |r|
  r.set("foo", "s1")
  r.set("bar", "s2")

  assert 2 == r.dbsize

  r.flushdb

  assert 0 == r.dbsize
end

test "FLUSHALL" do
  redis_mock(:flushall => lambda { "+FLUSHALL" }) do
    redis = Redis.new(OPTIONS.merge(:port => 6380))

    assert "FLUSHALL" == redis.flushall
  end
end
Something went wrong with that request. Please try again.