Commit 37f8f6a0 authored by Marcel Stör's avatar Marcel Stör
Browse files

Small overhaul

Fixes #2724
parent c50d007f
...@@ -22,21 +22,25 @@ Function used to connect to Redis server. ...@@ -22,21 +22,25 @@ Function used to connect to Redis server.
`redis.connect(host, [port])` `redis.connect(host, [port])`
#### Parameters #### Parameters
- `host`: Redis host name or address - `host` Redis host name or address
- `port`: Redis database port. Default value is 6379. - `port` Redis database port. Default value is 6379.
#### Returns #### Returns
Object with rest of the functions. Object with rest of the functions.
## subscribe() !!! important
You need to start calling this `connect()` function to obtain a Redis object. All other functions are invoked on this object. Note the difference between `redis.connect()` (single dot) and `redis:subscribe()` (colon).
## redis:subscribe()
Subscribe to a Redis channel. Subscribe to a Redis channel.
#### Syntax #### Syntax
`redis:subscribe(channel, handler)` `redis:subscribe(channel, handler)`
#### Parameters #### Parameters
- `channel`: Channel name - `channel` Channel name
- `handler`: Handler function that will be called on new message in subscribed channel - `handler` Handler function that will be called on new message in subscribed channel
#### Returns #### Returns
`nil` `nil`
...@@ -48,8 +52,8 @@ Publish a message to a Redis channel. ...@@ -48,8 +52,8 @@ Publish a message to a Redis channel.
`redis:publish(channel, message)` `redis:publish(channel, message)`
#### Parameters #### Parameters
- `channel`: Channel name - `channel` Channel name
- `message`: Message to publish - `message` Message to publish
#### Returns #### Returns
`nil` `nil`
...@@ -61,12 +65,12 @@ Unsubscribes from a channel. ...@@ -61,12 +65,12 @@ Unsubscribes from a channel.
`redis:unsubscribe(channel)` `redis:unsubscribe(channel)`
#### Parameters #### Parameters
- `channel`: Channel name to unsubscribe from - `channel` Channel name to unsubscribe from
#### Returns #### Returns
`nil` `nil`
#### redis:close() ## redis:close()
Function to close connection to Redis server. Function to close connection to Redis server.
#### Syntax #### Syntax
...@@ -78,9 +82,11 @@ None ...@@ -78,9 +82,11 @@ None
#### Returns #### Returns
`nil` `nil`
#### Example ## Example
```lua ```lua
local redis = dofile("redis.lua").connect(host, port) local redis = dofile("redis.lua").connect(host, port)
redis:publish("chan1", foo") redis:publish("chan1", "foo")
redis:subscribe("chan1", function(channel, msg) print(channel, msg) end) redis:subscribe("chan1", function(channel, msg)
print(channel, msg)
end)
``` ```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment