Skip to content

Commit

Permalink
Added redis db selection to setupRedis API method
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Burkalev authored and Konstantin Burkalev committed Apr 21, 2014
1 parent 7f65954 commit ce747f2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = function(grunt) {
options: {
process: function (content, srcpath) {
return content.replace(/\s*(\-\-)?\s*ngx\.log.*/g,'')
.replace(/\s*require.*debug\.var_dump.*/g,'')
.replace(/\s*(\-\-)?\s*var_dump.*/g,'');
}
}
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Table of Contents
* [Installation](#installation)
* [Dependencies](#dependencies)
* [Methods](#methods)
* [setupRedis](#setupredishost-port)
* [setupRedis](#setupredishost-port-db)
* [addConnection](#addconnectionsid-wampproto)
* [removeConnection](#removeconnectionregid)
* [receiveData](#receivedataregid-data)
Expand Down Expand Up @@ -95,7 +95,7 @@ Actually, you do not need to do anything. Just take any WAMP client and make a c
Methods
========

setupRedis(host, port)
setupRedis(host, port, db)
------------------------------------------

Configure and initialize connection to Redis server.
Expand All @@ -104,6 +104,7 @@ Parameters:

* **host** - Redis server host or Redis unix socket path
* **port** - Redis server port (in case of use network connection). Omit for socket connection.
* **db** - Redis database index to select

Returns:

Expand Down
2 changes: 1 addition & 1 deletion build/headers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- Date: 16.03.14
--

ngx.header["Server"] = "wiola/Lua v0.1"
ngx.header["Server"] = "wiola/Lua v0.3.1"

local wsProto = ngx.req.get_headers()["Sec-WebSocket-Protocol"]

Expand Down
19 changes: 14 additions & 5 deletions build/wiola.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ local redisLib = require "resty.redis"
local redis = redisLib:new()

local _M = {
_VERSION = '0.2'
_VERSION = '0.3.1'
}

_M.__index = _M

local wamp_features = {
agent = "wiola/Lua v0.2",
agent = "wiola/Lua v0.3.1",
roles = {
broker = {
features = {
Expand Down Expand Up @@ -92,15 +92,24 @@ end
--
-- host - redis host or unix socket
-- port - redis port in case of network use or nil
-- db - redis database to select
--
-- returns connection flag, error description
--
function _M.setupRedis(host, port)
function _M.setupRedis(host, port, db)
local redisOk, redisErr

if port == nil then
return redis:connect(host)
redisOk, redisErr = redis:connect(host)
else
return redis:connect(host, port)
redisOk, redisErr = redis:connect(host, port)
end

if redisOk and db ~= nil then
redis:select(db)
end

return redisOk, redisErr
end

--
Expand Down
2 changes: 1 addition & 1 deletion src/wiola/headers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- Date: 16.03.14
--

ngx.header["Server"] = "wiola/Lua v0.1"
ngx.header["Server"] = "wiola/Lua v0.3.1"

local wsProto = ngx.req.get_headers()["Sec-WebSocket-Protocol"]

Expand Down
21 changes: 16 additions & 5 deletions src/wiola/wiola.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
local redisLib = require "resty.redis"
local redis = redisLib:new()

require "debug.var_dump"

local _M = {
_VERSION = '0.2'
_VERSION = '0.3.1'
}

_M.__index = _M

local wamp_features = {
agent = "wiola/Lua v0.2",
agent = "wiola/Lua v0.3.1",
roles = {
broker = {
features = {
Expand Down Expand Up @@ -93,15 +95,24 @@ end
--
-- host - redis host or unix socket
-- port - redis port in case of network use or nil
-- db - redis database to select
--
-- returns connection flag, error description
--
function _M.setupRedis(host, port)
function _M.setupRedis(host, port, db)
local redisOk, redisErr

if port == nil then
return redis:connect(host)
redisOk, redisErr = redis:connect(host)
else
return redis:connect(host, port)
redisOk, redisErr = redis:connect(host, port)
end

if redisOk and db ~= nil then
redis:select(db)
end

return redisOk, redisErr
end

--
Expand Down

0 comments on commit ce747f2

Please sign in to comment.