public static final java.lang.String |
SETANDDECR |
"for index = 3, ARGV[2] + 2, 1 do\r\n\tlocal low = ARGV[index] * ARGV[1]\r\n\tlocal high = (ARGV[index] + 1) * ARGV[1]\r\n\tlocal decremented = false\r\n\tlocal nonZero = false;\r\n\tfor i = (high - 1), low, -1 do\r\n\t\tif not decremented then\r\n\t\t\tif redis.call(\'getbit\', KEYS[1], i) == 1 then\r\n\t\t\t\tredis.call(\'setbit\', KEYS[1], i, 0)\r\n\t\t\t\tdecremented = true\r\n\t\t\telse\r\n\t\t\t\tredis.call(\'setbit\', KEYS[1], i, 1)\r\n\t\t\t\tnonZero = true\r\n\t\t\tend\r\n\t\telse\r\n\t\t\tif redis.call(\'getbit\', KEYS[1], i) == 1 then\r\n\t\t\t\tnonZero = true\r\n\t\t\tend\r\n\t\tend\r\n\tend\r\n\tif not nonZero then\r\n\t\tredis.call(\'setbit\', KEYS[2], ARGV[index], 0)\r\n\tend\r\nend" |
public static final java.lang.String |
SETANDINCR |
"for index = 3, ARGV[2] + 2, 1 do\r\n\tredis.call(\'setbit\', KEYS[2], ARGV[index], 1)\r\n\tlocal low = ARGV[index] * ARGV[1]\r\n\tlocal high = (ARGV[index] + 1) * ARGV[1]\r\n\tlocal incremented = false\r\n\tfor i = (high - 1), low, -1 do\r\n\t\tif redis.call(\'getbit\', KEYS[1], i) == 0 then\r\n\t\t\tredis.call(\'setbit\', KEYS[1], i, 1)\r\n\t\t\tincremented = true\r\n\t\t\tbreak\r\n\t\telse\r\n\t\t\tredis.call(\'setbit\', KEYS[1], i, 0)\r\n\t\tend\r\n\tend\r\nend" |