Skip to content

cRedisClient - Redis Client ​

Overview ​

cRedisClient is a simple and easy-to-use Redis database client written in VB6/VBA. It supports the Redis RESP protocol and provides common Redis command interfaces, including connection management, basic operations, data structure operations, and transactions.

Features ​

  • Supports basic Redis commands (GET, SET, DEL, EXISTS, KEYS, etc.)
  • Supports multiple data structures: String, Hash, List, Set, Sorted Set
  • Supports pipeline mode
  • Supports transaction mode
  • Automatic reconnection mechanism (enabled by default)
  • Built-in heartbeat keep-alive
  • Supports Redis password authentication and ACL authentication (Redis 6.0+)
  • Supports multiple database switching
  • Synchronous operations, simple and easy to use

Documentation ​

Properties ​

PropertyTypeDescription
HostStringGet Redis server address
PortLongGet Redis server port
ConnectedBooleanGet connection status (internal flag)
IsConnectedBooleanGet actual Socket connection status
UsernameStringGet ACL authentication username
DbIndexLongGet or set current database index (0-15)
TimeoutDoubleGet or set timeout in seconds
AutoReconnectBooleanGet or set auto-reconnect (default True)
HeartbeatIntervalLongGet or set heartbeat interval in seconds (default 30)
InTransactionBooleanGet if in transaction
InPipelineBooleanGet if in pipeline mode
LastErrorStringGet last error message
SocketcWinsockGet underlying Socket object

Notes ​

  1. Connection Management: Remember to call DisConnect method to release connection when done
  2. Error Handling: Check connection status and LastError property before and after operations
  3. Timeout Settings: Set Timeout property appropriately based on network environment
  4. Data Types: All values in Redis are stored as strings, numeric operations require conversion
  5. Transaction Safety: Commands in transactions are not executed until Exec or Discard is called
  6. Batch Operations: Use MGet, MSet and other batch operations to improve performance
  7. Resource Release: Set object to Nothing when no longer in use

Dependencies ​

  • cWinsock - Socket communication component
  • ToolsUtf8 - UTF-8 encoding/decoding tool
  • Dictionary - For HGetAll to return dictionary object

Quick Start ​

vb
Dim oRedis As New cRedisClient

' Connect to local Redis server
If oRedis.Connect() Then
    Debug.Print "Connected successfully!"

    ' Set key-value
    oRedis.Set_ "name", "Zhang San"

    ' Get value
    Debug.Print "Name: " & oRedis.Get_("name")

    ' Disconnect
    oRedis.DisConnect
Else
    Debug.Print "Connection failed: " & oRedis.LastError
End If

License ​

Please refer to the main project documentation for license information.

VB6 and LOGO copyright of Microsoft Corporation