github.com/IBM-Swift/Kitura-redis

Swift Redis library


Keywords
client, database, redis, swift, swift-library
License
Apache-2.0

Documentation

KituraRedis

Build Status Build Status

Swift Redis library

KituraRedis is a Swift library for interacting with a Redis database using.

It is dependent on the BlueSocket and KituraSyS modules.

Build:

  • swift build (Mac OS X)
  • swift build -Xcc -fblocks (Linux)

Running Tests:

This example uses Docker to run Redis detached with the required password defined in Tests/SwiftRedis/password.txt.

  • docker run -d -p 6379:6379 redis:alpine redis-server --requirepass password123
  • swift test

Usage:

import Foundation
import SwiftRedis

let redis = Redis()

redis.connect(host: "localhost", port: 6379) { (redisError: NSError?) in
    if let error = redisError {
        print(error)
    }
    else {
        print("Connected to Redis")
        // set a key
        redis.set("Redis", value: "on Swift") { (result: Bool, redisError: NSError?) in
            if let error = redisError {
                print(error)
            }
            // get the same key
            redis.get("Redis") { (string: RedisString?, redisError: NSError?) in
                if let error = redisError {
                    print(error)
                }
                else if let string = string?.asString {
                    print("Redis \(string)")
                }
            }
        }
    }
}