4 import org.specs.mock.Mockito
5 import org.mockito.Mock._
6 import org.mockito.Mockito._
7 import org.mockito.Mockito.doNothing
9 object KeySpaceOperationsSpec extends Specification with Mockito {
11 "Redis Client Key Operations" should {
12 var client: RedisTestClient = null
13 var connection: Connection = null
16 connection = mock[Connection]
17 client = new RedisTestClient(connection)
20 "return all keys matching" in {
21 connection.readResponse returns "akey anotherkey adiffkey"
23 connection.write("KEYS a*\r\n") was called
26 "return a random key" in {
27 connection.readResponse returns "+somerandonkey"
28 client.randomKey mustEqual "somerandonkey"
29 connection.write("RANDOMKEY\r\n") was called
33 connection.readBoolean returns true
34 client.rename("a", "b") must beTrue
35 connection.write("RENAME a b\r\n") was called
38 "rename a key only if destintation doesn't exist" in {
39 connection.readBoolean returns false
40 client.renamenx("a", "b") must beFalse
41 connection.write("RENAMENX a b\r\n") was called
44 "tell the size of the db, # of keys" in {
45 connection.readInt returns 4
46 client.dbSize mustEqual 4
47 connection.write("DBSIZE\r\n") was called