13dc593ccc186ff4c153f60e53b348e96d70a038
[redis.git] / client-libraries / scala / src / main / scala / com / redis / Operations / KeySpaceOperations.scala
1 package com.redis.operations
2
3 /**
4 * Redis key space operations
5 *
6 */
7
8 trait KeySpaceOperations{
9
10 val connection: Connection
11 var db: Int
12
13 // KEYS
14 // returns all the keys matching the glob-style pattern.
15 def keys(pattern: String): Array[String] = {
16 connection.write("KEYS "+pattern+"\r\n")
17 connection.readResponse.toString.split(" ")
18 }
19
20 // RANDKEY
21 // return a randomly selected key from the currently selected DB.
22 def randomKey: String = {
23 connection.write("RANDOMKEY\r\n")
24 connection.readResponse.toString.split('+')(1)
25 }
26
27 // RENAME (oldkey, newkey)
28 // atomically renames the key oldkey to newkey.
29 def rename(oldkey: String, newkey: String): Boolean = {
30 connection.write("RENAME "+oldkey+" "+newkey+"\r\n")
31 connection.readBoolean
32 }
33
34 // RENAMENX (oldkey, newkey)
35 // rename oldkey into newkey but fails if the destination key newkey already exists.
36 def renamenx(oldkey: String, newkey: String): Boolean = {
37 connection.write("RENAMENX "+oldkey+" "+newkey+"\r\n")
38 connection.readBoolean
39 }
40
41 // DBSIZE
42 // return the size of the db.
43 def dbSize: Int = {
44 connection.write("DBSIZE\r\n")
45 connection.readInt
46 }
47 }