9951 explained code solutions for 126 technologies


lua-redisPrepend value to list using rpush


local redis = (require 'redis').connect('127.0.0.1', 6379)
redis:rpush('list_key', 'val')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

list_key

key of the list

'val'

value to prepend

rpush

prepends specified value to the Redis list


Usage example

local redis = (require 'redis').connect('127.0.0.1', 6379)
redis:rpush('list4', 'd')
redis:rpush('list4', 'c')
local list = redis:lrange('list4', 0, 1)
print(table.concat(list, ', '))
output
d, c