Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for pub-sub #48

Closed
mna opened this issue Nov 24, 2016 · 10 comments
Closed

Support for pub-sub #48

mna opened this issue Nov 24, 2016 · 10 comments

Comments

@mna
Copy link

mna commented Nov 24, 2016

Apologies if I missed something, but it seems like pub-sub is currently not supported? From what I see, when calling command, it does both a write and a read of the response on the socket, and there's no finer-grained method to just emit a write and a separate one for the reads, which are required for pub-sub (you call [P]SUBSCRIBE with a write, and then wait for messages by reading on the socket - it typically can't be used for other writes except to subscribe/unsubscribe to/from other channels).

For example, the redigo package in Go has separate Send/Flush calls to write, and Receive to read, and a convenience Do method that combines them for the common commands that immediately return a value (https://godoc.org/github.com/garyburd/redigo/redis#Conn). It also provides a PubSubConn type as convenience, built from the Send/Flush/Receive primitives (https://godoc.org/github.com/garyburd/redigo/redis#PubSubConn).

@surendratiwari3
Copy link

hi i added the pub-sub support. but there is one thing you have to open 2 redis connection 1 will listen for subscribe (redis messages) and other is used to do command to redis.

@surendratiwari3
Copy link

but in the main.swift you need to make changes as per your requirements.

@jazeelkt
Copy link

jazeelkt commented Dec 9, 2016

@surendratiwari3 Can you please provide an example on how to use your implementation?

@surendratiwari3
Copy link

do {
try client.command("SUBSCRIBE", params: ["hello"])

    print("Sending 'PING' to Redis server at \(client1.address):\(client1.port)")
    let response11 = try client1.command("PING", params: []).toString()
    print("Response: \(response11)")

    while true
    {
            let response2 = try client.read().toArray()
            var count = 0
            for element in response2
            {
                    count = count+1
                    let content = (element as! RespBulkString).content
                    if count==3
                    {
                            //published key
                            print(content)
                            //sending the command to redis
                            print("Sending HMGET \(content) to Redis server at \(client1.address):\(client1.port)")
                            let balance_res = try client1.command("HMGET", params: ["\(content)", "balance"]).toArray()
                            //get the balance from the redis
                            for ebal in balance_res
                            {
                                    let bal = (ebal as! RespBulkString).content
                                    print("Response: \(bal)")
                            }
                    }
            }
    }

} catch {
print("Encountered error (error)")
fatalError("(error)")
}

@surendratiwari3
Copy link

surendratiwari3 commented Dec 14, 2016

please declare the client and client1 like this:

let client = try Redbird()
let client_ip = try Redbird(config: RedbirdConfig(address: "127.0.0.1"))

let client1 = try Redbird()
let client_ip1 = try Redbird(config: RedbirdConfig(address: "127.0.0.1"))

@jazeelkt
Copy link

Thanks @surendratiwari3 , got it working. Great job !!

@surendratiwari3
Copy link

surendratiwari3 commented Dec 16, 2016

will you please do the same comment in the my pull request so they will accept it. and also please endorse me on linkledin . https://www.linkedin.com/in/surendra-tiwari-ab569a15?trk=nav_responsive_tab_profile
please also give comment also on linkedin

@cwoloszynski
Copy link

I'm looking to dynamically change the list of topics that my pubsub connection subscribes to. It appears that the current Redbird code only lets me subscribe to one topic and then blocks.

Is there any way to allow me to send additional commands (subscribe/unsubscribe) while I am listening for messages using Redbird?

@surendratiwari3
Copy link

yeah i provided a way to achieve that just take my pull request and enjoy!

@tanner0101
Copy link
Member

Added in #56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants