Skip to content

Introduction to Redisun

Redisun is a lightweight, high-performance Redis client based on smart-socket designed for the Java platform. It supports asynchronous non-blocking I/O operations and provides memory key-value storage access capabilities compatible with Redis servers.

💡 Core Features

  • Lightweight Design: The core code consists of only a few classes, the jar package is only 33KB, and resource usage is minimal
  • High-Performance Communication: Based on smart-socket Java AIO implementation, strong single-threaded processing capabilities, low resource consumption
  • Connection Multiplexing Technology: Innovative connection multiplexing mechanism, one connection can handle multiple concurrent requests simultaneously
  • RESP Protocol Support: Complete support for Redis Serialization Protocol (RESP), compatible with Redis servers

Here is a simple usage example showing how to use Redisun for basic Redis operations:

import tech.smartboot.redisun.Redisun;
public class BasicExample {
public static void main(String[] args) {
// Create Redisun client instance
Redisun redisun = Redisun.create(options ->
options.setAddress("127.0.0.1:6379") // Set Redis server address
.debug(true) // Enable debug mode
);
try {
// Set key-value pair
boolean setResult = redisun.set("hello", "world");
System.out.println("SET operation result: " + setResult);
// Get key value
String getResult = redisun.get("hello");
System.out.println("GET operation result: " + getResult);
// Delete key
int delResult = redisun.del("hello");
System.out.println("DEL operation result: " + delResult);
} finally {
// Close client, release resources
redisun.close();
}
}
}

Redisun also supports more Redis commands, such as sorted set operations:

// Add elements to sorted set
int zaddResult = redisun.zadd("myzset", 1.0, "member1");
System.out.println("ZADD operation result: " + zaddResult);
// Optional parameter settings
boolean setResultWithOptions = redisun.set("key", "value", cmd ->
cmd.expire(60) // Set 60-second expiration
.setIfNotExists() // Set only if key does not exist
);
System.out.println("SET operation with options result: " + setResultWithOptions);

Through these examples, you can see that Redisun’s API design is simple and intuitive, making it easy to integrate into your projects.

Redisun is continuously expanding support for Redis commands. Here is the current command implementation status:

CommandDescriptionImplementation ClassNotes
HELLOServer handshake and authenticationHelloCommandSupports authentication and protocol negotiation
SETSet key-value pairsSetCommandComplete option support: NX, XX, EX, PX, PXAT, KEEPTTL
GETGet the value of a keyGetCommandBasic key-value retrieval
DELDelete one or more keysDelCommandSupports multi-key deletion
ZADDAdd members to sorted setZAddCommandBasic sorted set member addition
SELECTSwitch databaseSelectCommandOnly executed during initial connection, does not support runtime switching
DBSIZEReturn the number of keys in the current databaseDBSizeCommandCount keys in current database
FLUSHALLClear all databasesFlushAllCommandDelete keys from all databases
FLUSHDBClear current databaseFlushDbCommandClear current database
EXISTSCheck if key existsExistsCommandCheck if one or more keys exist
INCRIncrement the integer value of a key by oneIncrCommandAtomic increment operation
DECRDecrement the integer value of a key by oneDecrCommandAtomic decrement operation
APPENDAppend a value to a keyAppendCommandString append operation
STRLENGet the length of a key’s valueStrlenCommandString length operation
HSETSet the string value of a hash fieldHSetCommandHash field set operation
HGETGet the value of a hash fieldHGetCommandHash field get operation
SADDAdd one or more members to a setSAddCommandSet member add operation
INCRBYIncrement the integer value of a key by the given numberIncrByCommandAtomic increment operation
DECRBYDecrement the integer value of a key by the given numberDecrByCommandAtomic decrement operation
MGETGet the values of all given keysMGetCommandGet multiple key values
MSETSet multiple key-value pairsMSetCommandSet multiple key-value pairs
EXPIRESet a timeout on a keyExpireCommandSupports NX, XX, GT, LT options
TTLGet the time to live for a keyTtlCommandReturns the remaining lifetime of a key in seconds
TYPEDetermine the type stored at a keyTypeCommandReturns the type stored at a key
LPUSHInsert elements at the head of a listLPushCommandInsert one or more elements at the head of a list
RPUSHInsert elements at the tail of a listRPushCommandInsert one or more elements at the tail of a list
LPOPRemove and return the first element of a listLPopCommandRemove and return the first element of a list
RPOPRemove and return the last element of a listRPopCommandRemove and return the last element of a list
ZREMRemove members from a sorted setZRemCommandRemove one or more members from a sorted set
ZRANGEReturn a range of members in a sorted setZRangeCommandReturn members in a specified index range of a sorted set
ZSCOREGet the score associated with the given member in a sorted setZScoreCommandGet the score of a specified member in a sorted set

We are actively expanding Redis command support. More commands will be included in future versions.

Redisun provides a powerful extension mechanism. You can easily implement custom Redis commands by extending the Command base class. This makes it simple to add support for any Redis commands not yet built into the library.

For detailed information on using custom commands to extend Redisun, please refer to our Extension Guide.