Created
August 13, 2014 20:51
-
-
Save stimms/a6bcdeb9248b7f85f5ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void EvalTest() | |
{ | |
var redisConnection = GetRedisConnection(); | |
redisConnection.StringSet("foo", 77); | |
redisConnection.StringSet("foo.count", 1); | |
string script = @"local currentval = redis.call('get', ARGV[1]) | |
local currentcount = redis.call('get', ARGV[1] .. '.count') | |
redis.call('incr', ARGV[1] .. '.count') | |
currentval = (currentval * (currentcount/(currentcount + 1))) + (ARGV[2]/(currentcount+1)) | |
redis.call('set', ARGV[1], currentval) | |
return currentval"; | |
var result = redisConnection.ScriptEvaluate(script, null, new RedisValue[] { "foo", 11 }, CommandFlags.None); | |
((int)result).Should().Be.EqualTo(44); | |
result = redisConnection.ScriptEvaluate(GetScriptHash(script), null, new RedisValue[] { "foo", 11 }, CommandFlags.None); | |
((int)result).Should().Be.EqualTo(33); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment