# Redisun
**Repository Path**: smartboot/redisun
## Basic Information
- **Project Name**: Redisun
- **Description**: Redisun:专注于Redis相关技术的开源项目,提供高效的数据结构存储、处理解决方案,支持多种应用场景,助力开发者实现高性能应用开发。
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: https://smartboot.tech/redisun
- **GVP Project**: No
## Statistics
- **Stars**: 16
- **Forks**: 1
- **Created**: 2025-10-21
- **Last Updated**: 2025-10-27
## Categories & Tags
**Categories**: cache-modules
**Tags**: smart-socket, Redis, Java, SpringBoot
## README

[](https://central.sonatype.com/artifact/tech.smartboot/redisun)
[](https://github.com/smartboot/redisun/blob/master/LICENSE)
Redisun is a lightweight Redis client based on [smart-socket](https://github.com/smartboot/smart-socket) designed for the Java platform. It supports asynchronous non-blocking I/O operations and provides high-performance Redis connection and command execution capabilities.
## Features
- **Lightweight Design**: Core code consists of only a few classes, with a jar size of only 33KB and minimal resource usage
- **High-performance Communication**: Based on smart-socket Java AIO implementation with strong single-thread processing capabilities and low resource consumption
- **Connection Multiplexing Technology**: Innovative connection multiplexing mechanism that allows one connection to handle multiple concurrent requests
- **RESP Protocol Support**: Full support for Redis Serialization Protocol (RESP), compatible with Redis servers
- **Command Extension Mechanism**: Provides a simple and easy-to-use command extension interface for adding custom Redis commands
- **Multi-database Support**: Supports Redis multi-database switching
- **Authentication Support**: Supports username/password authentication for Redis servers
## Core Components
- **Redisun**: Core client class that provides connection management and command execution functionality
- **Command**: Abstract base class for Redis commands, supporting custom command extensions
- **RESP**: Redis serialization protocol parser, supporting multiple data types
- **RedisMessageProcessor**: Message processor responsible for parsing Redis server responses
- **RedisSession**: Session manager that maintains client-server session state
- **RedisunOptions**: Client configuration options class for setting connection parameters
## Installation
### Maven
```xml
tech.smartboot
redisun
1.0.0
```
### Gradle
```gradle
implementation 'tech.smartboot:redisun:1.0.0'
```
## Quick Start
### Basic Usage
```java
import tech.smartboot.redisun.Redisun;
Redisun redisun = Redisun.create(options -> {
options.setAddress("redis://127.0.0.1:6379");
// Or use an address with authentication information
// options.setAddress("redis://username:password@127.0.0.1:6379");
});
// Set key-value
boolean setResult = redisun.set("mykey", "myvalue");
System.out.println("SET command result: " + setResult);
// Get value by key
String getResult = redisun.get("mykey");
System.out.println("GET command result: " + getResult);
// Execute sorted set command
int zaddResult = redisun.zadd("myzset", 1.0, "member1");
System.out.println("ZADD command result: " + zaddResult);
// Delete key
int delResult = redisun.del("mykey");
System.out.println("DEL command result: " + delResult);
redisun.close();
```
### Advanced SET Command Usage
```java
Redisun redisun = Redisun.create(options -> {
options.setAddress("redis://127.0.0.1:6379");
});
// Basic set
redisun.set("key1", "value1");
// Set only if key does not exist (NX option)
boolean nxResult = redisun.set("key2", "value2", cmd -> cmd.setIfNotExists());
// Set only if key exists (XX option)
boolean xxResult = redisun.set("key1", "newvalue", cmd -> cmd.setIfExists());
// Set expiration time (seconds)
redisun.set("key3", "value3", cmd -> cmd.expire(60));
// Set expiration time (milliseconds)
redisun.set("key4", "value4", cmd -> cmd.expireMs(30000));
// Expire at specified time
redisun.set("key5", "value5", cmd -> cmd.expireAt(new Date(System.currentTimeMillis() + 60000)));
// Keep key's time to live
redisun.set("key1", "anotherValue", cmd -> cmd.keepTTL());
redisun.close();
```
### Advanced Configuration
```java
Redisun redisun = Redisun.create(options -> {
// Set server address
options.setAddress("redis://127.0.0.1:6379")
// Set database
.setDatabase(1)
// Enable debug mode
.debug(true);
});
```
## Supported Commands
Redisun is continuously expanding its Redis command support. Here's the current status of command implementation:
### ✅ Fully Supported Commands
| Command | Description | Implementation Class | Notes |
|---------|-------------|---------------------|-------|
| `HELLO` | Server handshake and authentication | [HelloCommand](src/main/java/tech/smartboot/redisun/cmd/HelloCommand.java) | Supports authentication and protocol negotiation |
| `SET` | Set key-value pairs | [SetCommand](src/main/java/tech/smartboot/redisun/cmd/SetCommand.java) | Full option support: NX, XX, EX, PX, PXAT, KEEPTTL |
| `GET` | Get the value of a key | [GetCommand](src/main/java/tech/smartboot/redisun/cmd/GetCommand.java) | Basic key-value retrieval |
| `DEL` | Delete one or more keys | [DelCommand](src/main/java/tech/smartboot/redisun/cmd/DelCommand.java) | Supports multiple key deletion |
| `ZADD` | Add members to a sorted set | [ZAddCommand](src/main/java/tech/smartboot/redisun/cmd/ZAddCommand.java) | Basic sorted set member addition |
| `SELECT` | Change the selected database | [SelectCommand](src/main/java/tech/smartboot/redisun/cmd/SelectCommand.java) | Only executed during initial connection, not supported at runtime |
| `DBSIZE` | Return the number of keys in the selected database | [DBSizeCommand](src/main/java/tech/smartboot/redisun/cmd/DBSizeCommand.java) | Count keys in current database |
| `FLUSHALL` | Remove all keys from all databases | [FlushAllCommand](src/main/java/tech/smartboot/redisun/cmd/FlushAllCommand.java) | Clear all databases |
| `FLUSHDB` | Remove all keys from the current database | [FlushDbCommand](src/main/java/tech/smartboot/redisun/cmd/FlushDbCommand.java) | Clear current database |
| `EXISTS` | Check if keys exist | [ExistsCommand](src/main/java/tech/smartboot/redisun/cmd/ExistsCommand.java) | Check existence of one or more keys |
| `INCR` | Increment the integer value of a key by one | [IncrCommand](src/main/java/tech/smartboot/redisun/cmd/IncrCommand.java) | Atomic increment operation |
| `DECR` | Decrement the integer value of a key by one | [DecrCommand](src/main/java/tech/smartboot/redisun/cmd/DecrCommand.java) | Atomic decrement operation |
| `APPEND` | Append a value to a key | [AppendCommand](src/main/java/tech/smartboot/redisun/cmd/AppendCommand.java) | String append operation |
| `STRLEN` | Get the length of the value stored in a key | [StrlenCommand](src/main/java/tech/smartboot/redisun/cmd/StrlenCommand.java) | String length operation |
| `HSET` | Set the string value of a hash field | [HSetCommand](src/main/java/tech/smartboot/redisun/cmd/HSetCommand.java) | Hash field set operation |
| `HGET` | Get the value of a hash field | [HGetCommand](src/main/java/tech/smartboot/redisun/cmd/HGetCommand.java) | Hash field get operation |
| `SADD` | Add one or more members to a set | [SAddCommand](src/main/java/tech/smartboot/redisun/cmd/SAddCommand.java) | Set member add operation |
| `INCRBY` | Increment the integer value of a key by the given amount | [IncrByCommand](src/main/java/tech/smartboot/redisun/cmd/IncrByCommand.java) | Atomic increment by operation |
| `DECRBY` | Decrement the integer value of a key by the given amount | [DecrByCommand](src/main/java/tech/smartboot/redisun/cmd/DecrByCommand.java) | Atomic decrement by operation |
| `MGET` | Get the values of all the given keys | [MGetCommand](src/main/java/tech/smartboot/redisun/cmd/MGetCommand.java) | Get multiple key values |
| `MSET` | Set multiple keys to multiple values | [MSetCommand](src/main/java/tech/smartboot/redisun/cmd/MSetCommand.java) | Set multiple key-value pairs |
| `TTL` | Get the time to live for a key | [TtlCommand](src/main/java/tech/smartboot/redisun/cmd/TtlCommand.java) | Get key expiration time in seconds |
| `TYPE` | Determine the type stored at key | [TypeCommand](src/main/java/tech/smartboot/redisun/cmd/TypeCommand.java) | Get the type of value stored at key |
| `LPUSH` | Insert all the specified values at the head of the list | [LPushCommand](src/main/java/tech/smartboot/redisun/cmd/LPushCommand.java) | Insert one or more elements to the head of a list |
| `RPUSH` | Insert all the specified values at the tail of the list | [RPushCommand](src/main/java/tech/smartboot/redisun/cmd/RPushCommand.java) | Insert one or more elements to the tail of a list |
| `LPOP` | Remove and return the first element of the list | [LPopCommand](src/main/java/tech/smartboot/redisun/cmd/LPopCommand.java) | Remove and get the first element in a list |
| `RPOP` | Remove and return the last element of the list | [RPopCommand](src/main/java/tech/smartboot/redisun/cmd/RPopCommand.java) | Remove and get the last element in a list |
| `ZREM` | Remove one or more members from a sorted set | [ZRemCommand](src/main/java/tech/smartboot/redisun/cmd/ZRemCommand.java) | Remove one or more members from a sorted set |
| `ZRANGE` | Return a range of members in a sorted set | [ZRangeCommand](src/main/java/tech/smartboot/redisun/cmd/ZRangeCommand.java) | Return a range of members in a sorted set, by index |
| `ZSCORE` | Get the score associated with the given member in a sorted set | [ZScoreCommand](src/main/java/tech/smartboot/redisun/cmd/ZScoreCommand.java) | Get the score associated with the given member in a sorted set |
| `EXPIRE` | Set a key's time to live in seconds | [ExpireCommand](src/main/java/tech/smartboot/redisun/cmd/ExpireCommand.java) | Supports NX, XX, GT, LT options |
### 🚧 In Progress / Planned Commands
We are actively working to expand Redis command support. Future releases will include more commands.
### 🛠 Custom Command Extension
Redisun provides a powerful extension mechanism. You can easily implement custom Redis commands by extending the [Command](src/main/java/tech/smartboot/redisun/Command.java) base class. This makes it simple to add support for any Redis command that isn't yet built into the library.
For detailed information on extending Redisun with custom commands, please refer to our [extension guide](#).
## Build and Test
Make sure Maven is installed, then run the following command:
```bash
mvn clean package
```
Run tests:
```bash
mvn test
```
## License
This project is licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt).
## Contributing
Pull requests and suggestions are welcome. Please refer to the project [issue tracker](https://github.com/smartboot/redisun/issues) for pending tasks.
## Contact
For questions or suggestions, please submit an issue or contact the project maintainer [三刀](https://github.com/smartdms).