9951 explained code solutions for 126 technologies


lua-redisHow to select db


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

:select

selects specified DB by number

(2)

select DB number 2


Usage example

local redis = (require 'redis').connect('127.0.0.1', 6379)
print(redis:get('key'))

redis:select(2)
print(redis:get('key'))
output
10
nil