1 package com.redis.operations
4 * Redis key space operations
8 trait KeySpaceOperations{
10 val connection: Connection
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(" ")
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)
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
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
42 // return the size of the db.
44 connection.write("DBSIZE\r\n")