new redis.Client
method, you can create a Client instance. The parameter for this method is the address of the target redis.new Client(url: string): Client
Parameter | Type | Description |
url | string | The address of the target redis server, for example, redis://<user>:<password>@<host>:<port>/<db_number> |
Methodology | Return Type | Description |
string | Obtain the value of the specified key. | |
string | Set the value of the specified key. | |
number | Delete existing keys. | |
number | Insert one or more values at the head of the list. | |
number | Insert one or more values at the tail of the list. | |
string | Remove and obtain the first element of the list. | |
string | Remove and obtain the last element of the list. | |
string[] | Obtain elements within the specified range from the list. | |
string | Obtain elements from the list by index. | |
number | Obtain the length of the list. | |
string | Set the value of elements in the list by index. | |
number | Remove elements from the list. | |
number | Set the fields and values in the hash table key. | |
string | Obtain the value stored in the specified field of the hash table. | |
number | Delete one or more hash table fields. | |
number | Obtain the number of fields in the hash table. | |
number | Add one or more members to the set. | |
number | Remove one or more members from the set. | |
boolean | Determine whether the member element is a member of the set key. | |
string[] | Return all members in the set. | |
string | Randomly return an element in the set. | |
string | Randomly remove and return an element in the set. |
import redis from "pts/redis";let client = new redis.Client("redis://:<password>@<host>:6379/0");export default function main() {let resp = client.set("key", "hello, world", 0);console.log(`redis set ${resp}`); // OKlet val = client.get("key");console.log(`redis get ${val}`); // hello, worldlet cnt = client.del("key");console.log(`redis del ${cnt}`); // 1let lpushResp = client.lPush("list", "foo");console.log(`redis lpush ${lpushResp}`); // OKlet lpopResp = client.lPop("list");console.log(`redis lpop ${lpopResp}`); // foolet listLen = client.lLen("list");console.log(`redis llen ${listLen}`); // 0let hashSetResp = client.hSet("hash", "k", 1); // [k1, v1, k2, v2, ...]console.log(`redis hset ${hashSetResp}`); // 1let hashGetResp = client.hGet("hash", "k");console.log(`redis hget ${hashGetResp}`); // 1let hashDelResp = client.hDel("hash", "k");console.log(`redis hdel ${hashDelResp}`); // 1let setAddResp = client.sAdd("set", "hello");console.log(`redis sadd ${setAddResp}`); // 1let setPopResp = client.sPop("set");console.log(`redis spop ${setPopResp}`); // hello}