9951 explained code solutions for 126 technologies


lua-redisRedis eval example


local redis = (require 'redis').connect('127.0.0.1', 6379)
local val = redis:eval("return redis.call('get', 't1');", 0)ctrl + c
require 'redis'

load Redis module for Lua

connect

connect to Redis server

'127.0.0.1', 6379

Redis host and port to connect to

eval

evaluates given LUA code directly on Redis server

return redis.call('get', 't1');

Redis LUA code will return value for t1 key


Usage example

local redis = (require 'redis').connect('127.0.0.1', 6379)
redis:set('t1', '123')
local val = redis:eval("return redis.call('get', 't1');", 0)
print(val)
output
123