1 package com.redis.operations
10 def getConnection(key: String): Connection
13 // Add the specified member to the set value stored at key.
14 def setAdd(key: String, value: String): Boolean = {
15 val connection = getConnection(key)
16 connection.write("SADD "+key+" "+value.length+"\r\n"+value+"\r\n")
17 connection.readBoolean
21 // Remove the specified member from the set value stored at key.
22 def setDelete(key: String, value: String): Boolean = {
23 val connection = getConnection(key)
24 connection.write("SREM "+key+" "+value.length+"\r\n"+value+"\r\n")
25 connection.readBoolean
29 // Return the number of elements (the cardinality) of the Set at key.
30 def setCount(key: String): Int = {
31 val connection = getConnection(key)
32 connection.write("SCARD "+key+"\r\n")
37 // Return all the members of the Set value at key.
38 def setMembers(key: String): Set[String] = {
39 val connection = getConnection(key)
40 connection.write("SMEMBERS "+key+"\r\n")
45 // Remove and return (pop) a random element from the Set value at key.
46 def setPop(key: String): String = {
47 val connection = getConnection(key)
48 connection.write("SPOP "+key+"\r\n")
53 // Move the specified member from one Set to another atomically.
54 def setMove(sourceKey: String, destKey: String, value: String): Boolean = {
55 val connection = getConnection(sourceKey)
56 connection.write("SMOVE "+sourceKey+" "+destKey+" "+value+"\r\n")
57 connection.readBoolean
61 // Test if the specified value is a member of the Set at key.
62 def setMemberExists(key: String, value: String): Boolean = {
63 val connection = getConnection(key)
64 connection.write("SISMEMBER "+key+" "+value.length+"\r\n"+value+"\r\n")
65 connection.readBoolean
69 // Return the intersection between the Sets stored at key1, key2, ..., keyN.
70 def setIntersect(keys: String*): Set[String] = {
71 val connection = getConnection(keys(0))
72 connection.write("SINTER "+keys.mkString(" ")+"\r\n")
77 // Compute the intersection between the Sets stored at key1, key2, ..., keyN, and store the resulting Set at dstkey.
78 def setInterStore(key: String, keys: String*): Boolean = {
79 val connection = getConnection(key)
80 connection.write("SINTERSTORE "+key+" "+keys.mkString(" ")+"\r\n")
81 connection.readBoolean
85 // Return the difference between the Set stored at key1 and all the Sets key2, ..., keyN.
86 def setDiff(keys: String*): Set[String] = {
87 val connection = getConnection(keys(0))
88 connection.write("SDIFF "+keys.mkString(" ")+"\r\n")
93 // Compute the difference between the Set key1 and all the Sets key2, ..., keyN, and store the resulting Set at dstkey.
94 def setDiffStore(key: String, keys: String*): Boolean = {
95 val connection = getConnection(key)
96 connection.write("SDIFFSTORE "+key+" "+keys.mkString(" ")+"\r\n")
97 connection.readBoolean
101 // Return the union between the Sets stored at key1, key2, ..., keyN.
102 def setUnion(keys: String*): Set[String] = {
103 val connection = getConnection(keys(0))
104 connection.write("SUNION "+keys.mkString(" ")+"\r\n")
109 // Compute the union between the Sets stored at key1, key2, ..., keyN, and store the resulting Set at dstkey.
110 def setUnionStore(key: String, keys: String*): Boolean = {
111 val connection = getConnection(key)
112 connection.write("SUNIONSTORE "+key+" "+keys.mkString(" ")+"\r\n")
113 connection.readBoolean