Skip to content

Files

Latest commit

8d4588a · Apr 11, 2021

History

History
160 lines (132 loc) · 3.21 KB

redis.adoc

File metadata and controls

160 lines (132 loc) · 3.21 KB

redis

redis.new([String][, String][, Number]) → Table

Create a new Redis client connection. The return value is an object for performing redis commands.

Arguments

Type Description

string

Address and port of Redis, default: 127.0.0.1:6379

string

Password, default: ""

number

Database, default: 0

Returns

Type Description

table

Object that you can index into to perform commands

Example

local redis = require 'redis'
local rdb = redis.new()
rdb.get('key')
...

close()

Close redis client connection.

del(String) → Number

Removes the specified keys. A key is ignored if it does not exist.

Arguments

Type Description

string

Key

Returns

Type Description

Number

The number of keys that were removed, 1 if successful, 0 otherwise

set(String, String) → Boolean

Set key to hold the string value. If key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful SET operation.

Arguments

Type Description

string

Key

string

Value

Returns

Type Description

boolean

If successful, true

get(String, String) → String

Get the value of key.

Arguments

Type Description

string

Key

Returns

Type Description

string

Value

incr(String) → _Number

Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation.

Arguments

Type Description

string

Key

Returns

Type Description

number

Value of key after the increment

hset(String, Table) → Boolean

Sets field in the hash stored at key to value from a table(map). If key does not exist, a new key holding a hash is created. If field already exists in the hash, it is overwritten.

Arguments

Type Description

string

Key

table

Map of fields and values

Returns

Type Description

boolean

If successful, true

hget(String, String) → String

Returns the value associated with field in the hash stored at key.

Arguments

Type Description

string

Key

string

Field

Returns

Type Description

string

Value

hdel(String, String) → Number

Removes the specified fields from the hash stored at key. Specified fields that do not exist within this hash are ignored. If key does not exist, it is treated as an empty hash and this command returns 0.

Arguments

Type Description

string

Key

string

Field

Returns

Type Description

number

Fields deleted