Skip to content

Commit

Permalink
Merge pull request rstudio#5 from rstudio/feature/default-score
Browse files Browse the repository at this point in the history
Allow default score value when score isn't provided
  • Loading branch information
cbarraford committed Oct 16, 2014
2 parents a3c2e2e + 70df9a8 commit 99052b6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

## 1.2.1 (2014-10-15)

### Feature
+ [PR](https://github.com/rstudio/redx/pull/5): Adds the ability to set a default score value when one is not provided.

## 1.2.0 (2014-10-14)

### Feature
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ The amount of time (in seconds) you wish the session to be "sticky", and consist
##### balance\_algorithm
The load balancing algorithm you want to use to balance traffic to your backends. The options are `least-score`, `most-score`, and `random`. `Random` is the default.

##### default\_score
The default score is the score that is inserted into backends in the case where a score is not provided (ie batch upating). If this config option isn't specified, it defaults to 0 (zero).

Load Balancing Algorithms
=========================

Expand Down
3 changes: 3 additions & 0 deletions conf/config.moon
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ M.stickiness = 0
-- Load Balancing Algorithm
-- "random" or "least-score" or "most-score"
M.balance_algorithm = 'random'

-- Default score value
M.default_score = 0
return M
14 changes: 10 additions & 4 deletions lua/src/lib/redis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ M.get_data = function(self, asset_type, asset_name)
return M.finish(red)
end
M.save_data = function(self, asset_type, asset_name, asset_value, score, overwrite)
if score == nil then
score = 0
end
if overwrite == nil then
overwrite = false
end
Expand All @@ -218,6 +215,12 @@ M.save_data = function(self, asset_type, asset_name, asset_value, score, overwri
if 'frontends' == _exp_0 then
local ok, err = red:set('frontend:' .. asset_name, asset_value)
elseif 'backends' == _exp_0 then
if config.default_score == nil then
config.default_score = 0
end
if score == nil then
score = config.default_score
end
red = M.connect(self)
if overwrite then
red:init_pipeline()
Expand Down Expand Up @@ -333,7 +336,10 @@ M.save_batch_data = function(self, data, overwrite)
local server = _list_1[_index_1]
if not (server == nil) then
library.log('adding backend: ' .. backend["name"] .. ' ' .. server)
red:zadd('backend:' .. backend["name"], 0, server)
if config.default_score == nil then
config.default_score = 0
end
red:zadd('backend:' .. backend["name"], config.default_score, server)
end
end
end
Expand Down
10 changes: 8 additions & 2 deletions src/lib/redis.moon
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,17 @@ M.get_data = (@, asset_type, asset_name) ->
library.log(@msg)
M.finish(red)

M.save_data = (@, asset_type, asset_name, asset_value, score=0, overwrite=false) ->
M.save_data = (@, asset_type, asset_name, asset_value, score, overwrite=false) ->
red = M.connect(@)
return nil if red == nil
switch asset_type
when 'frontends'
ok, err = red\set('frontend:' .. asset_name, asset_value)
when 'backends'
if config.default_score == nil
config.default_score = 0
if score == nil
score = config.default_score
red = M.connect(@)
red\init_pipeline() if overwrite
red\del('backend:' .. asset_name) if overwrite
Expand Down Expand Up @@ -213,7 +217,9 @@ M.save_batch_data = (@, data, overwrite=false) ->
for server in *backend['servers']
unless server == nil
library.log('adding backend: ' .. backend["name"] .. ' ' .. server)
red\zadd('backend:' .. backend["name"], 0, server)
if config.default_score == nil
config.default_score = 0
red\zadd('backend:' .. backend["name"], config.default_score, server)
M.commit(@, red, "failed to save data: ")
M.finish(red)

Expand Down

0 comments on commit 99052b6

Please sign in to comment.