Giter Site home page Giter Site logo

redis's Introduction

Redis

Swift 3.0 License MIT Slack Status Build Status

A pure Swift client for Redis.

Features

  • Pub/Sub
  • Pipeline with DISCARD
  • Scripts
  • All commands

Installation

Add Redis to your Package.swift

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/Zewo/Redis", majorVersion: 0, minor: 3)
    ]
)

Using

let redis = try Redis("127.0.0.1", 6379)
try redis.command(.SET("foo", "bar"))

All commands and its parameters are defined in CommandTypeEnum enum, with parameters in the same order as Redis docs. The command function returns the same response from Redis.

Commands with milliseconds (SETEX/PSETEX, EXPIRE/PEXPIRE, etc) have a Bool parameter to send or return in milliseconds. It's always the last parameter.

At this time, there is some commands exceptions:

  • SORT - To be implemented
  • MIGRATE, WAIT, SCAN - These are commands to manage the server. A discussion could be opened to implement it or don't.
  • Server commands - Same as above

Pipeline

Pipeline works by issuing commands inside a closure:

try redis.pipeline {
	try redis.command(.SET("foobar", "foo bar"))
	try redis.command(.SET("foo", "bar"))
}

If you need to WATCH a key, use the first argument. In case of an error, it'll be returned as nil.

try redis.pipeline(["foo"]) {
	try redis.command(.SET("foobar", "foo bar"))
	try redis.command(.SET("foo", "bar"))
}

PubSub

WARNING: This is a first draft and the syntax is open to discussion. Beware of changes.

PubSub can subscribe to multiple channels at once, but you have to unsubscribe one at time.

let redis = try Redis("127.0.0.1", 6379)

let pubsub = PubSub(conn: redis)
try pubsub.subscribe(["foo-channel", "bar-channel"]) { message in 
	if message["data"] as? String == "stop" {
		print("Stahp \(message["channel"])!")
		pubsub.unsubscribe(message["channel"] as! String)
	} else {
		print("Keep walking \(message["channel"])...")
	}
}

Contributing

Pull requests are welcome, there is a lot to do.

We recommend using the Vagrant from redis-py to test everything.

Community

Slack

Join us on Slack.

License

Redis is released under the MIT license. See LICENSE for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.