Redis์์๋ ๋ค์๊ณผ ๊ฐ์ด CLI๋ฅผ ํตํด Lua ์คํฌ๋ฆฝํธ๋ฅผ ์คํํฉ๋๋ค .
$ redis-cli --eval debug_script.lua key1 key2 key3 key4 , arg1 arg2
๋ฐ๋ผ์ ๋ด Lua ์คํฌ๋ฆฝํธ๋ 4 ๊ฐ์ ํค์ 2 ๊ฐ์ ์ธ์๋ฅผ๋ฐ์ต๋๋ค.
์ด์ Node.js์์ ๋์ผํ ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๊ณ ์ถ์ต๋๋ค.
๋ด ์ฑ์์ Redis๋ฅผ ๊ฐ์ ธ ์ค๋ ๋ฐ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
Lua ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ๊ธฐ์ํ redisClient.eval (...) ํจ์์ ์ธ์์ ๋ํด ์๋ ค์ฃผ๋ ์์ ๋ฅผ ์ฐพ์ง ๋ชปํ์ต๋๋ค.
๋ฐ๋ผ์ ๋๋ ์๋ ํ ์์๋ ์์์ ๊ฒ์ ์น๊ณ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ์๋ฌด๊ฒ๋ ์๋ํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋ด ์ง๋ฌธ : node.js๋ฅผ ์ฌ์ฉํ์ฌ ์๋ ๋ช ๋ น์ ์คํํ๋ ๋ฐฉ๋ฒ์ผ๋ก CLI (command-line-interface)๋ฅผ ํตํด ์คํํ ๋์ ๋์ผํ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํฉ๋๋ค.
$ redis-cli --eval debug_script.lua key1 key2 key3 key4 , arg1 arg2
--eval
๋ '์ง์ง'redis ๋ช
๋ น์ด ์๋๋ผ redis-cli์ ์ถ๊ฐ ์ต์
์
๋๋ค. ๊ทธ๋ฌ๋ ์ฌ์ ํ ์ํ๋ ์์
์ ์ํ ํ ์ ์์ต๋๋ค.
'use strict'
const redis = require('redis')
const client = redis.createClient()
const fs = require('fs')
client.eval(fs.readFileSync('./test.lua'), 2, 'key1', 'key2', 'first', 'second', function(err, res) {
console.log(arguments);
});
์ผ๋ถ ๋ณด์ ๊ฒ์ฌ๋ฅผ ์ํํ๊ณ ์ถ์ ์ ์์ผ๋ฉฐ EVAL
์๋ --eval
๋ณด๋ค ๋ ๋ง์ ์ต์
์ด ํ์ํฉ๋๋ค. --eval
์ EVAL
์ ์ฐจ์ด์ ์ ๋ํ ์์ธํ ๋ด์ฉ์ https://redis.io/topics/rediscli#running -lua-scripts๋ฅผ
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
--eval
๋ '์ง์ง'redis ๋ช ๋ น์ด ์๋๋ผ redis-cli์ ์ถ๊ฐ ์ต์ ์ ๋๋ค. ๊ทธ๋ฌ๋ ์ฌ์ ํ ์ํ๋ ์์ ์ ์ํ ํ ์ ์์ต๋๋ค.์ผ๋ถ ๋ณด์ ๊ฒ์ฌ๋ฅผ ์ํํ๊ณ ์ถ์ ์ ์์ผ๋ฉฐ
EVAL
์๋--eval
๋ณด๋ค ๋ ๋ง์ ์ต์ ์ด ํ์ํฉ๋๋ค.--eval
์EVAL
์ ์ฐจ์ด์ ์ ๋ํ ์์ธํ ๋ด์ฉ์ https://redis.io/topics/rediscli#running -lua-scripts๋ฅผ