Home

Awesome

<p align="center"> <a href="https://tedis.silkjs.org/" target="_blank" rel="noopener noreferrer"><img src="./doc/.vuepress/public/icons/android-chrome-192x192.png" alt="tedis logo"></a> </p> <p align="center"> <a href="https://travis-ci.org/silkjs/tedis"><img src="https://img.shields.io/travis/silkjs/tedis.svg" alt="travis"></a> <a href="https://github.com/silkjs/tedis/issues"><img src="https://img.shields.io/github/issues-raw/silkjs/tedis.svg" alt="issues"></a> <a href="https://github.com/silkjs/tedis"><img src="https://img.shields.io/github/license/silkjs/tedis.svg" alt="license"></a> <a href="https://www.npmjs.com/package/tedis"><img src="https://img.shields.io/npm/v/tedis.svg" alt="package"></a> <a href='https://codecov.io/gh/silkjs/tedis'><img src='https://img.shields.io/codecov/c/github/silkjs/tedis.svg' alt='Coverage Status' /></a> <a href="javascript:void(0)" ><img src="https://img.shields.io/github/tag/silkjs/tedis.svg" alt="tag"></a> <br> <a href="javascript:void(0)" ><img src="https://img.shields.io/github/issues-pr/silkjs/tedis.svg" alt="pr"></a> <a href="javascript:void(0)" ><img src="https://img.shields.io/github/release/silkjs/tedis.svg" alt="release"></a> <a href="javascript:void(0)" ><img src="https://img.shields.io/github/languages/top/silkjs/tedis.svg" alt="languages"></a> <a href="javascript:void(0)" ><img src="https://img.shields.io/github/languages/code-size/silkjs/tedis.svg" alt="size"></a> <a href="javascript:void(0)" ><img src="https://img.shields.io/github/last-commit/silkjs/tedis.svg" alt="commit"></a> </p> <h2 align="center">Supporting Tedis</h2>

Introduction

What is tedis

Tedis write with typescript, it's the client of redis for nodejs, support async with ts and commonjs

Installation

yarn add tedis

Getting started

commonjs

const { Tedis, TedisPool } = require("tedis");

typescript

import { Tedis, TedisPool } from "tedis";
// no auth
const tedis = new Tedis({
  port: 6379,
  host: "127.0.0.1"
});

// auth
const tedis = new Tedis({
  port: 6379,
  host: "127.0.0.1",
  password: "your_password"
});

tls

const tedis = new Tedis({
  port: 6379,
  host: "127.0.0.1",
  tls: {
    key: fs.readFileSync(__dirname + "/client_server/client_key.pem"),
    cert: fs.readFileSync(__dirname + "/client_server/client_cert.pem")
  }
});

TedisPool

// no auth
const pool = new TedisPool({
  port: 6379,
  host: "127.0.0.1"
});

// auth
const pool = new TedisPool({
  port: 6379,
  host: "127.0.0.1",
  password: "your_password"
});
const tedis = await pool.getTedis();
// ... do some commands
pool.putTedis(tedis);

tls

const tedis = new TedisPool({
  port: 6379,
  host: "127.0.0.1",
  tls: {
    key: fs.readFileSync(__dirname + "/client_server/client_key.pem"),
    cert: fs.readFileSync(__dirname + "/client_server/client_cert.pem")
  }
});

Example

/**
 * core
 */
await tedis.command("SET", "key1", "Hello");
// "OK"
await tedis.command("SET", "key2", "World");
// "OK"

/**
 * key
 */
await tedis.keys("*");
// []
await tedis.exists("a");
// 0

/**
 * string
 */
await tedis.set("mystring", "hello");
// "OK"
await tedis.get("mystring");
// "hello"

/**
 * hash
 */
await tedis.hmset("myhash", {
  name: "tedis",
  age: 18
});
// "OK"
await tedis.hgetall("myhash");
// {
//   "name": "tedis",
//   "age": "18"
// }

/**
 * list
 */
await tedis.lpush("mylist", "hello", "a", "b", "c", "d", 1, 2, 3, 4);
// 9
await tedis.llen("mylist");
// 9

Type interface

base

pool

key

string

hash

list

set

zset