File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
Sources/RediStack/Commands
Tests/RediStackIntegrationTests Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,28 @@ extension RedisClient {
101
101
return self . delete ( keys)
102
102
}
103
103
104
+ /// Checks the existence of the provided keys in the database.
105
+ ///
106
+ /// [https://redis.io/commands/exists](https://redis.io/commands/exists)
107
+ /// - Parameter keys: A list of keys whose existence will be checked for in the database.
108
+ /// - Returns: The number of provided keys which exist in the database.
109
+ public func exists( _ keys: [ RedisKey ] ) -> EventLoopFuture < Int > {
110
+ let args : [ RESPValue ] = keys. map {
111
+ RESPValue ( from: $0)
112
+ }
113
+ return self . send ( command: " EXISTS " , with: args)
114
+ . map ( to: Int . self)
115
+ }
116
+
117
+ /// Checks the existence of the provided keys in the database.
118
+ ///
119
+ /// [https://redis.io/commands/exists](https://redis.io/commands/exists)
120
+ /// - Parameter keys: A list of keys whose existence will be checked for in the database.
121
+ /// - Returns: The number of provided keys which exist in the database.
122
+ public func exists( _ keys: RedisKey ... ) -> EventLoopFuture < Int > {
123
+ return self . exists ( keys)
124
+ }
125
+
104
126
/// Sets a timeout on key. After the timeout has expired, the key will automatically be deleted.
105
127
/// - Note: A key with an associated timeout is often said to be "volatile" in Redis terminology.
106
128
///
Original file line number Diff line number Diff line change @@ -37,6 +37,22 @@ final class BasicCommandsTests: RediStackIntegrationTestCase {
37
37
XCTAssertEqual ( third, 2 )
38
38
}
39
39
40
+ func test_exists( ) throws {
41
+ try self . connection. set ( " first " , to: " 1 " ) . wait ( )
42
+ let first = try connection. exists ( " first " ) . wait ( )
43
+ XCTAssertEqual ( first, 1 )
44
+
45
+ try self . connection. set ( " second " , to: " 2 " ) . wait ( )
46
+ let firstAndSecond = try connection. exists ( " first " , " second " ) . wait ( )
47
+ XCTAssertEqual ( firstAndSecond, 2 )
48
+
49
+ let secondAndThird = try connection. exists ( " second " , " third " ) . wait ( )
50
+ XCTAssertEqual ( secondAndThird, 1 )
51
+
52
+ let third = try connection. exists ( " third " ) . wait ( )
53
+ XCTAssertEqual ( third, 0 )
54
+ }
55
+
40
56
func test_expire( ) throws {
41
57
try connection. set ( #function, to: " value " ) . wait ( )
42
58
XCTAssertNotNil ( try connection. get ( #function) . wait ( ) )
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ extension BasicCommandsTests {
8
8
static let __allTests__BasicCommandsTests = [
9
9
( " test_delete " , test_delete) ,
10
10
( " test_echo " , test_echo) ,
11
+ ( " test_exists " , test_exists) ,
11
12
( " test_expire " , test_expire) ,
12
13
( " test_ping " , test_ping) ,
13
14
( " test_select " , test_select) ,
You can’t perform that action at this time.
0 commit comments