Last active
September 26, 2022 12:01
-
-
Save wankdanker/8db0398c9bc4e6a9753a17922f5952ce to your computer and use it in GitHub Desktop.
happend LUA script for redis
This file contains hidden or 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
const Redis = require('ioredis') | |
const redis = new Redis() | |
redis.defineCommand("happend", { | |
numberOfKeys: 2, | |
lua: ` | |
local current = redis.call("hget", KEYS[1], KEYS[2]) | |
if current == nil or current == false then | |
current = ARGV[1] | |
else | |
current = current .. ARGV[1] | |
end | |
redis.call("hset", KEYS[1], KEYS[2], current) | |
return #current | |
`, | |
}); | |
(async () => { | |
let newLength = await redis.happend('key', 'sub-key', 'value') | |
})() |
This file contains hidden or 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
local current = redis.call("hget", KEYS[1], KEYS[2]) | |
if current == nil or current == false then | |
current = ARGV[1] | |
else | |
current = current .. ARGV[1] | |
end | |
redis.call("hset", KEYS[1], KEYS[2], current) | |
return #current |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment