English | ไทย
In-memory key-value cache server written in Rust, designed as a lightweight Redis-like alternative.
It speaks the Redis RESP protocol sufficiently for basic commands and can be used with ioredis
from Node.js.
This project is developed by SIAMINNOVATOR CO., LTD. (Thailand) as an open source alternative for those who need a Redis-like cache server without worrying about Redis licensing issues.
Option 1: One-line install (requires Rust)
curl -fsSL https://raw.githubusercontent.com/SiamInnovator/rust-cache/main/install-universal.sh | bashOption 2: From source
git clone https://github.com/SiamInnovator/rust-cache.git
cd rust-cache
./install.shOption 3: Using Cargo (if published to crates.io)
cargo install rust-cache- Basic commands:
PING,GET,SET,DEL,EXPIRE,TTL,KEYS,INCR,DECR,INCRBY,DECRBY,FLUSHALL - Optional TTL support for
SETviaEXoption - In-memory store using sharded concurrent map (
dashmap) - Background cleanup task for expired keys
- Async TCP server based on Tokio, multiple concurrent clients
- Authentication support (username/password)
- Rate limiting for failed login attempts
- Configurable memory limits and buffer sizes
- JSON data storage support
git clone https://github.com/SiamInnovator/rust-cache.git
cd rust-cache
cargo build --releaseThe resulting binary will be at:
target/release/rust-cache
target/release/rust-cache-cliThe server searches for config files in this order (first found wins):
RUST_CACHE_CONFIGenvironment variable (explicit override)/etc/rust-cache/rust-cache.conf(system-wide config)~/.config/rust-cache/rust-cache.toml(user config)./rust-cache.toml(local, current working directory)
If no config file is found, defaults are used:
- Listen on
127.0.0.1:7777 - Auto-detect total RAM on Linux and use ~50% as max memory
- Use 4 KB socket read buffer per connection
Example:
# Use system config
sudo mkdir -p /etc/rust-cache
sudo cp rust-cache.toml /etc/rust-cache/rust-cache.conf
./target/release/rust-cache
# Or use user config
mkdir -p ~/.config/rust-cache
cp rust-cache.toml ~/.config/rust-cache/
./target/release/rust-cache
# Or override with env
RUST_CACHE_CONFIG=/path/to/custom.toml ./target/release/rust-cacheSee rust-cache.toml for all available options.
Yes! rust-cache stores data as binary (bytes), so you can store JSON strings directly.
Just serialize your JSON on the client side before SET, and deserialize after GET:
Node.js example:
const Redis = require('ioredis');
// Without authentication
const redis = new Redis({ host: '127.0.0.1', port: 7777 });
// With password
const redis = new Redis({ host: '127.0.0.1', port: 7777, password: 'your-password' });
// With username and password
const redis = new Redis({ host: '127.0.0.1', port: 7777, username: 'admin', password: 'your-password' });
// Store JSON
const data = { name: 'test', value: 123 };
await redis.set('mykey', JSON.stringify(data));
// Retrieve JSON
const jsonStr = await redis.get('mykey');
const parsed = JSON.parse(jsonStr);CLI example:
rust-cache-cli
rust-cache> SET user:1 '{"name":"John","age":30}'
OK
rust-cache> GET user:1
{"name":"John","age":30}Install ioredis in your Node.js project:
npm install ioredisExample client (see examples/ioredis-client.js):
# Without authentication
node examples/ioredis-client.js
# With password (configure in examples/.env)
# Create examples/.env file with: REDIS_PASSWORD=your-password
node examples/ioredis-client.js
# With username and password
# Create examples/.env file with:
# REDIS_USERNAME=admin
# REDIS_PASSWORD=your-password
node examples/ioredis-client.jsThe example will connect to 127.0.0.1:7777, run PING, SET, GET, EXPIRE, TTL, and log results.
Install as a systemd service:
sudo cp rust-cache.service.example /etc/systemd/system/rust-cache.service
sudo systemctl daemon-reload
sudo systemctl enable rust-cache
sudo systemctl start rust-cacheAfter changing config, restart:
sudo systemctl restart rust-cacheThis software is provided under the MIT License. You are free to use, modify, and
distribute it without restriction, including for commercial purposes. See the LICENSE
file for the full text.
เซิร์ฟเวอร์ cache แบบ key-value ในหน่วยความจำที่เขียนด้วย Rust ออกแบบมาเป็นทางเลือก
ที่เบาและเร็วกว่า Redis รองรับโปรโตคอล Redis RESP สำหรับคำสั่งพื้นฐานและใช้งานร่วมกับ
ioredis จาก Node.js ได้
โปรเจกต์นี้พัฒนาโดย SIAMINNOVATOR CO., LTD. (ประเทศไทย) เพื่อเป็นทางเลือก open source ที่ไม่มีปัญหาลิขสิทธิ์สำหรับผู้ที่ต้องการใช้ Redis-like cache server โดยไม่ต้องกังวลเรื่องลิขสิทธิ์ของ Redis
วิธีที่ 1: ติดตั้งด้วยคำสั่งเดียว (ต้องมี Rust)
curl -fsSL https://raw.githubusercontent.com/SiamInnovator/rust-cache/main/install-universal.sh | bashวิธีที่ 2: จาก source code
git clone https://github.com/SiamInnovator/rust-cache.git
cd rust-cache
./install.shวิธีที่ 3: ใช้ Cargo (ถ้า publish ไป crates.io แล้ว)
cargo install rust-cache- คำสั่งพื้นฐาน:
PING,GET,SET,DEL,EXPIRE,TTL,KEYS,INCR,DECR,INCRBY,DECRBY,FLUSHALL - รองรับ TTL สำหรับ
SETผ่าน optionEX - เก็บข้อมูลในหน่วยความจำด้วย sharded concurrent map (
dashmap) - มี background task ทำความสะอาด key ที่หมดอายุ
- Async TCP server ใช้ Tokio รองรับหลาย client พร้อมกัน
- รองรับการยืนยันตัวตน (username/password)
- Rate limiting สำหรับการ login ที่ล้มเหลว
- กำหนดขีดจำกัดหน่วยความจำและขนาด buffer ได้
- รองรับการเก็บข้อมูล JSON
git clone https://github.com/SiamInnovator/rust-cache.git
cd rust-cache
cargo build --releaseBinary ที่ได้จะอยู่ที่:
target/release/rust-cache
target/release/rust-cache-cliเซิร์ฟเวอร์จะค้นหาไฟล์ config ตามลำดับนี้ (ใช้ตัวแรกที่เจอ):
- ตัวแปร environment
RUST_CACHE_CONFIG(override) /etc/rust-cache/rust-cache.conf(config ระดับระบบ)~/.config/rust-cache/rust-cache.toml(config ของผู้ใช้)./rust-cache.toml(config ในโฟลเดอร์ปัจจุบัน)
ถ้าไม่เจอไฟล์ config จะใช้ค่า default:
- ฟังที่
127.0.0.1:7777 - ตรวจจับ RAM ทั้งหมดบน Linux อัตโนมัติและใช้ ~50% เป็น max memory
- ใช้ socket read buffer 4 KB ต่อ connection
ตัวอย่าง:
# ใช้ config ระดับระบบ
sudo mkdir -p /etc/rust-cache
sudo cp rust-cache.toml /etc/rust-cache/rust-cache.conf
./target/release/rust-cache
# หรือใช้ config ของผู้ใช้
mkdir -p ~/.config/rust-cache
cp rust-cache.toml ~/.config/rust-cache/
./target/release/rust-cache
# หรือ override ด้วย env
RUST_CACHE_CONFIG=/path/to/custom.toml ./target/release/rust-cacheดูตัวเลือกทั้งหมดได้ใน rust-cache.toml
ได้เลย! rust-cache เก็บข้อมูลเป็น binary (bytes) ดังนั้นสามารถเก็บ JSON string ได้โดยตรง
แค่ serialize JSON ฝั่ง client ก่อน SET และ deserialize หลัง GET:
ตัวอย่าง Node.js:
const Redis = require('ioredis');
// ไม่มี authentication
const redis = new Redis({ host: '127.0.0.1', port: 7777 });
// มี password
const redis = new Redis({ host: '127.0.0.1', port: 7777, password: 'your-password' });
// มี username และ password
const redis = new Redis({ host: '127.0.0.1', port: 7777, username: 'admin', password: 'your-password' });
// เก็บ JSON
const data = { name: 'test', value: 123 };
await redis.set('mykey', JSON.stringify(data));
// ดึง JSON
const jsonStr = await redis.get('mykey');
const parsed = JSON.parse(jsonStr);ตัวอย่าง CLI:
rust-cache-cli
rust-cache> SET user:1 '{"name":"John","age":30}'
OK
rust-cache> GET user:1
{"name":"John","age":30}ติดตั้ง ioredis ในโปรเจกต์ Node.js:
npm install ioredisตัวอย่าง client (ดู examples/ioredis-client.js):
# ไม่มี authentication
node examples/ioredis-client.js
# มี password (ตั้งค่าใน examples/.env)
# สร้างไฟล์ examples/.env แล้วใส่: REDIS_PASSWORD=your-password
node examples/ioredis-client.js
# มี username และ password
# สร้างไฟล์ examples/.env แล้วใส่:
# REDIS_USERNAME=admin
# REDIS_PASSWORD=your-password
node examples/ioredis-client.jsตัวอย่างจะเชื่อมต่อไปที่ 127.0.0.1:7777 แล้วรัน PING, SET, GET, EXPIRE, TTL และแสดงผลลัพธ์
ติดตั้งเป็น systemd service:
sudo cp rust-cache.service.example /etc/systemd/system/rust-cache.service
sudo systemctl daemon-reload
sudo systemctl enable rust-cache
sudo systemctl start rust-cacheหลังจากแก้ config แล้ว restart:
sudo systemctl restart rust-cacheซอฟต์แวร์นี้เปิดให้ใช้งานได้อย่างเสรี ไม่มีค่าใช้จ่าย และไม่มีข้อจำกัดในการใช้งาน
เชิงพาณิชย์ ดูรายละเอียดเพิ่มเติมในไฟล์ LICENSE
พัฒนาโดย SIAMINNOVATOR CO., LTD. (ประเทศไทย)
