11# Redis Client for V
22
33This module provides a Redis client implementation in V that supports the
4- Redis Serialization Protocol (RESP) with a type-safe interface for common Redis commands.
4+ Redis Serialization Protocol (RESP) versions 2 (RESP2) and 3 (RESP3) with
5+ a type-safe interface for common Redis commands.
56
67## Features
78
@@ -12,7 +13,6 @@ Redis Serialization Protocol (RESP) with a type-safe interface for common Redis
1213- ** Memory Efficient** : Pre-allocated buffers for minimal allocations
1314
1415## Quick Start
15-
1616``` v
1717module main
1818
@@ -22,10 +22,14 @@ fn main() {
2222 // Connect to Redis
2323 // Uncomment passwod line if authentication is needed
2424 mut db := redis.connect(redis.Config{
25- host: 'localhost'
26- // password: 'your_password'
27- port: 6379
25+ // Available Config options (none of which need to be specified if you want the defauilts):
26+ // host: 'localhost' - default
27+ // password: 'your_password' - no default, you need to supply password if your redis server
28+ // is set up to need one
29+ // port: 6379 - default
30+ // tls: false - default, set to true for ssl connection
2831 })!
32+ println('Server supports RESP${db.version} protocol')
2933
3034 // Set and get values
3135 db.set('name', 'Alice')!
@@ -46,7 +50,6 @@ fn main() {
4650## Supported Commands
4751
4852### Key Operations
49-
5053``` v ignore
5154// Set value
5255db.set('key', 'value')!
@@ -66,12 +69,11 @@ db.expire('key', 60)! // 60 seconds
6669```
6770
6871### Hash Operations
69-
7072``` v ignore
7173// Set hash fields
7274db.hset('user:1', {
7375 'name': 'Bob',
74- 'age': 30 ,
76+ 'age': '30' ,
7577})!
7678
7779// Get single field
@@ -83,15 +85,14 @@ println(user_data) // Output: {'name': 'Bob', 'age': '30'}
8385```
8486
8587### Pipeline Operations
86-
8788``` v ignore
8889// Start pipeline
8990db.pipeline_start()
9091
9192// Queue commands
92- db.incr('counter')
93- db.set('name', 'Charlie')
94- db.get[string]('name')
93+ db.incr('counter')!
94+ db.set('name', 'Charlie')!
95+ db.get[string]('name')!
9596
9697// Execute and get responses
9798responses := db.pipeline_execute()!
@@ -101,7 +102,6 @@ for resp in responses {
101102```
102103
103104### Custom Commands
104-
105105``` v ignore
106106// Run raw commands
107107resp := db.cmd('SET', 'custom', 'value')!
@@ -129,12 +129,10 @@ result := db.get[string]('nonexistent') or {
129129```
130130
131131## Connection Management
132-
133132``` v ignore
134133config := redis.Config{
135134 host: 'redis.server'
136135 port: 6379
137- version: 2 // RESP2 protocol
138136}
139137
140138mut db := redis.connect(config)!
@@ -148,4 +146,4 @@ defer {
1481461 . ** Reuse Connections** : Maintain connections instead of creating new ones
1491472 . ** Use Pipelines** : Batch commands for high-throughput operations
1501483 . ** Prefer Integers** : Use numeric types for counters and metrics
151- 4 . ** Specify Types** : Always specify return types for get operations
149+ 4 . ** Specify Types** : Always specify return types for get operations
0 commit comments