test-valkey-glide-rb 0.0.1.pre.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rubocop.yml +69 -0
- data/.rubocop_todo.yml +22 -0
- data/AGENTS.md +224 -0
- data/CLAUDE.md +130 -0
- data/CONTRIBUTING.md +115 -0
- data/DEVELOPER.md +390 -0
- data/README.md +268 -0
- data/Rakefile +99 -0
- data/examples/README.md +55 -0
- data/examples/cluster.rb +24 -0
- data/examples/opentelemetry.rb +50 -0
- data/examples/pipelining.rb +29 -0
- data/examples/standalone.rb +22 -0
- data/examples/statistics.rb +24 -0
- data/lib/valkey/bindings.rb +319 -0
- data/lib/valkey/commands/bitmap_commands.rb +86 -0
- data/lib/valkey/commands/cluster_commands.rb +259 -0
- data/lib/valkey/commands/connection_commands.rb +318 -0
- data/lib/valkey/commands/function_commands.rb +255 -0
- data/lib/valkey/commands/generic_commands.rb +525 -0
- data/lib/valkey/commands/geo_commands.rb +87 -0
- data/lib/valkey/commands/hash_commands.rb +592 -0
- data/lib/valkey/commands/hyper_log_log_commands.rb +51 -0
- data/lib/valkey/commands/json_commands.rb +389 -0
- data/lib/valkey/commands/list_commands.rb +348 -0
- data/lib/valkey/commands/module_commands.rb +125 -0
- data/lib/valkey/commands/pubsub_commands.rb +237 -0
- data/lib/valkey/commands/scripting_commands.rb +287 -0
- data/lib/valkey/commands/server_commands.rb +961 -0
- data/lib/valkey/commands/set_commands.rb +220 -0
- data/lib/valkey/commands/sorted_set_commands.rb +971 -0
- data/lib/valkey/commands/stream_commands.rb +636 -0
- data/lib/valkey/commands/string_commands.rb +371 -0
- data/lib/valkey/commands/transaction_commands.rb +175 -0
- data/lib/valkey/commands/vector_search_commands.rb +271 -0
- data/lib/valkey/commands.rb +68 -0
- data/lib/valkey/errors.rb +41 -0
- data/lib/valkey/native/aarch64-unknown-linux-gnu/libglide_ffi.so +0 -0
- data/lib/valkey/native/x86_64-unknown-linux-gnu/libglide_ffi.so +0 -0
- data/lib/valkey/opentelemetry.rb +207 -0
- data/lib/valkey/pipeline.rb +20 -0
- data/lib/valkey/pubsub_callback.rb +10 -0
- data/lib/valkey/request_error_type.rb +10 -0
- data/lib/valkey/request_type.rb +436 -0
- data/lib/valkey/response_type.rb +20 -0
- data/lib/valkey/utils.rb +267 -0
- data/lib/valkey/version.rb +5 -0
- data/lib/valkey.rb +617 -0
- metadata +107 -0
data/DEVELOPER.md
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
# Developer Guide
|
|
2
|
+
|
|
3
|
+
This document describes how to set up your development environment to build and test the Valkey GLIDE Ruby client (`valkey-rb`).
|
|
4
|
+
|
|
5
|
+
## Development Overview
|
|
6
|
+
|
|
7
|
+
The Valkey GLIDE Ruby client consists of **Ruby** application code and a **Rust FFI** native library. Ruby talks to [glide-core](https://github.com/valkey-io/valkey-glide/tree/main/glide-core) through the [`glide-ffi`](https://github.com/valkey-io/valkey-glide/tree/main/ffi) crate, exposed as `libglide_ffi.so` (Linux) or `libglide_ffi.dylib` (macOS) via the [`ffi`](https://github.com/ffi/ffi) gem.
|
|
8
|
+
|
|
9
|
+
| Layer | Technology | Location |
|
|
10
|
+
|-------|------------|----------|
|
|
11
|
+
| Application API | Ruby | `lib/valkey.rb`, `lib/valkey/commands/` |
|
|
12
|
+
| FFI bindings | Ruby FFI | `lib/valkey/bindings.rb` |
|
|
13
|
+
| Native bridge | Rust `cdylib` | `lib/valkey/libglide_ffi.{so,dylib}` |
|
|
14
|
+
| Core driver | Rust `glide-core` | Built from [valkey-glide](https://github.com/valkey-io/valkey-glide) |
|
|
15
|
+
|
|
16
|
+
This architecture matches the **Go** and **Python sync** clients (C FFI), not the Java (JNI) or Python async (PyO3 + UDS) stacks.
|
|
17
|
+
|
|
18
|
+
## Project Structure
|
|
19
|
+
|
|
20
|
+
```text
|
|
21
|
+
valkey-glide-ruby/
|
|
22
|
+
├── lib/
|
|
23
|
+
│ ├── valkey.rb # Client, pipelining, response conversion
|
|
24
|
+
│ └── valkey/
|
|
25
|
+
│ ├── bindings.rb # FFI definitions
|
|
26
|
+
│ ├── native/ # Platform-specific native libraries (in gem)
|
|
27
|
+
│ │ ├── x86_64-unknown-linux-gnu/
|
|
28
|
+
│ │ └── aarch64-unknown-linux-gnu/
|
|
29
|
+
│ ├── commands/ # Command modules per data type
|
|
30
|
+
│ ├── opentelemetry.rb # OTel init and sampling
|
|
31
|
+
│ ├── pipeline.rb # Pipeline helper
|
|
32
|
+
│ ├── request_type.rb # Command enum (maps to glide-core)
|
|
33
|
+
│ ├── response_type.rb # Response enum
|
|
34
|
+
│ └── errors.rb # Ruby exception types
|
|
35
|
+
├── valkey-glide/ # Git submodule (valkey-io/valkey-glide)
|
|
36
|
+
│ └── ffi/ # Rust FFI crate (build target)
|
|
37
|
+
├── test/
|
|
38
|
+
│ ├── valkey/ # Standalone server tests
|
|
39
|
+
│ ├── cluster/ # Cluster tests
|
|
40
|
+
│ ├── lint/ # Shared lint suites
|
|
41
|
+
│ └── support/helper/ # Test helpers (client, cluster, SSL)
|
|
42
|
+
├── bin/
|
|
43
|
+
│ ├── setup # bundle install
|
|
44
|
+
│ └── console # IRB with gem loaded
|
|
45
|
+
├── .github/workflows/
|
|
46
|
+
│ ├── CI.yml # RuboCop + test matrix
|
|
47
|
+
│ └── cd.yml # Build and publish gem
|
|
48
|
+
├── valkey.gemspec
|
|
49
|
+
├── Gemfile
|
|
50
|
+
└── Rakefile # test:valkey, test:cluster, native:build
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Prerequisites
|
|
54
|
+
|
|
55
|
+
### Software Dependencies
|
|
56
|
+
|
|
57
|
+
- **Ruby** 2.6+ (3.x recommended for development)
|
|
58
|
+
- **Bundler**
|
|
59
|
+
- **git**
|
|
60
|
+
- **Valkey** or Redis OSS (for integration tests)
|
|
61
|
+
- **Docker** (optional; matches CI setup)
|
|
62
|
+
|
|
63
|
+
To **rebuild** the native FFI library from source:
|
|
64
|
+
|
|
65
|
+
- **Rust** (`rustup`)
|
|
66
|
+
- **GCC** / Xcode command-line tools
|
|
67
|
+
- **cmake**, **pkg-config**, **openssl** / **libssl-dev**
|
|
68
|
+
- Clone of [valkey-glide](https://github.com/valkey-io/valkey-glide) at a compatible release tag
|
|
69
|
+
|
|
70
|
+
### Valkey Installation
|
|
71
|
+
|
|
72
|
+
See the [Valkey installation guide](https://valkey.io/topics/installation/) to install `valkey-server` and `valkey-cli`.
|
|
73
|
+
|
|
74
|
+
**Ubuntu / Debian (standalone testing):**
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
sudo apt update -y
|
|
78
|
+
sudo apt install -y ruby-full build-essential
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**macOS:**
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
brew install ruby
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Clone and Local Setup
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
git clone --recurse-submodules https://github.com/valkey-io/valkey-glide-ruby.git
|
|
91
|
+
cd valkey-glide-ruby
|
|
92
|
+
bin/setup # runs bundle install
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
If you've already cloned without submodules:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
git submodule update --init --recursive
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Load the gem from the checkout without installing:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
export RUBYOPT="-I$(pwd)/lib"
|
|
105
|
+
bundle exec ruby -r valkey -e 'puts Valkey::VERSION'
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Interactive console:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
bundle exec bin/console
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Build Native FFI from Source
|
|
115
|
+
|
|
116
|
+
This repository includes [valkey-glide](https://github.com/valkey-io/valkey-glide) as a Git submodule. Rake tasks are provided to build the native FFI library.
|
|
117
|
+
|
|
118
|
+
### Prerequisites for Building
|
|
119
|
+
|
|
120
|
+
- **Rust toolchain**: Install via [rustup](https://rustup.rs/)
|
|
121
|
+
- **Protobuf compiler**: `protoc` (required for glide-core)
|
|
122
|
+
|
|
123
|
+
### Build with Rake
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Build the native FFI library (release mode)
|
|
127
|
+
rake native:build
|
|
128
|
+
|
|
129
|
+
# This will:
|
|
130
|
+
# 1. Initialize the valkey-glide submodule if needed
|
|
131
|
+
# 2. Build the Rust FFI library in release mode
|
|
132
|
+
# 3. Output: valkey-glide/ffi/target/release/libglide_ffi.{so,dylib}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Available Rake Tasks
|
|
136
|
+
|
|
137
|
+
| Task | Description |
|
|
138
|
+
|------|-------------|
|
|
139
|
+
| `rake native:build` | Build the native FFI library (release mode) |
|
|
140
|
+
| `rake native:build_debug` | Build the native FFI library (debug mode) |
|
|
141
|
+
| `rake native:clean` | Clean native build artifacts |
|
|
142
|
+
| `rake native:submodule` | Initialize/update the valkey-glide submodule |
|
|
143
|
+
| `rake native:package` | Copy built library to `lib/valkey/` for gem packaging |
|
|
144
|
+
|
|
145
|
+
### Verify the Build
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
bundle exec ruby -e 'require "valkey"; c = Valkey.new; puts c.ping; c.close'
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Updating the Submodule
|
|
152
|
+
|
|
153
|
+
To update to a newer version of valkey-glide:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
cd valkey-glide
|
|
157
|
+
git fetch origin
|
|
158
|
+
git checkout v2.4.0 # or desired tag/branch
|
|
159
|
+
cd ..
|
|
160
|
+
git add valkey-glide
|
|
161
|
+
git commit -m "Update valkey-glide submodule to v2.4.0"
|
|
162
|
+
|
|
163
|
+
# Rebuild the native library
|
|
164
|
+
rake native:build
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Rust Linters (when changing FFI)
|
|
168
|
+
|
|
169
|
+
From `valkey-glide/ffi/`:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
rustup component add clippy rustfmt
|
|
173
|
+
cargo clippy --all-features --all-targets -- -D warnings
|
|
174
|
+
cargo fmt --manifest-path ./Cargo.toml --all
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
See [ffi/README.md](https://github.com/valkey-io/valkey-glide/blob/main/ffi/README.md) in valkey-glide for C header generation (`cbindgen`) if needed.
|
|
178
|
+
|
|
179
|
+
## Running Tests
|
|
180
|
+
|
|
181
|
+
Tests use **Minitest**. The suite is split into standalone (`test/valkey/`) and cluster (`test/cluster/`) groups.
|
|
182
|
+
|
|
183
|
+
### Start Valkey (standalone)
|
|
184
|
+
|
|
185
|
+
Default test configuration (see `test/test_helper.rb`):
|
|
186
|
+
|
|
187
|
+
| Variable | Default | Purpose |
|
|
188
|
+
|----------|---------|---------|
|
|
189
|
+
| `VALKEY_PORT` | `6379` | Plain TCP |
|
|
190
|
+
| `VALKEY_SSL_PORT` | `6380` | TLS (optional) |
|
|
191
|
+
| `TIMEOUT` | `5.0` | Client timeout |
|
|
192
|
+
| DB | `15` | Test database |
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Example: Docker standalone (matches CI)
|
|
196
|
+
docker run -d --name valkey-test -p 6379:6379 valkey/valkey:8 \
|
|
197
|
+
valkey-server --enable-module-command yes
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Start Valkey Cluster
|
|
201
|
+
|
|
202
|
+
Cluster tests expect six nodes on `127.0.0.1:7000`–`7005`. CI uses `grokzen/redis-cluster:7.0.15`.
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
docker run -d --name redis-cluster -p 7000-7005:7000-7005 grokzen/redis-cluster:7.0.15
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Run Tests
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
# All default (standalone) tests
|
|
212
|
+
bundle exec rake test
|
|
213
|
+
# or
|
|
214
|
+
bundle exec rake test:valkey
|
|
215
|
+
|
|
216
|
+
# Cluster tests only
|
|
217
|
+
bundle exec rake test:cluster
|
|
218
|
+
|
|
219
|
+
# Verbose output (also enabled when CI=1)
|
|
220
|
+
CI=1 bundle exec rake test:valkey
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### SSL Tests
|
|
224
|
+
|
|
225
|
+
Generate test certificates:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
ruby test/fixtures/ssl/generate_certs.rb
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Start TLS Valkey on port 6380 (see `.github/workflows/CI.yml` for a full Docker example).
|
|
232
|
+
|
|
233
|
+
### Module Tests (JSON, Bloom, Search)
|
|
234
|
+
|
|
235
|
+
CI copies prebuilt modules into `test/fixtures/`:
|
|
236
|
+
|
|
237
|
+
- `redisjson.so` — JSON commands
|
|
238
|
+
- `redisbloom.so` — Bloom filters
|
|
239
|
+
- `redisearch.so` — Vector / FT commands
|
|
240
|
+
|
|
241
|
+
Load modules when starting Valkey if you run module-specific tests locally.
|
|
242
|
+
|
|
243
|
+
### Environment Overrides
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
VALKEY_PORT=6379 TIMEOUT=10 bundle exec rake test:valkey
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Linters
|
|
250
|
+
|
|
251
|
+
### RuboCop
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
bundle exec rubocop
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
CI runs RuboCop on every push and pull request (see `.github/workflows/CI.yml`).
|
|
258
|
+
|
|
259
|
+
Auto-correct safe offenses:
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
bundle exec rubocop -A
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Configuration: `.rubocop.yml`, `.rubocop_todo.yml`.
|
|
266
|
+
|
|
267
|
+
## Contributing New Valkey Commands
|
|
268
|
+
|
|
269
|
+
When adding a command, check whether it already exists in [glide-core](https://github.com/valkey-io/valkey-glide/blob/main/glide-core/src/request_type.rs) and [command_request.proto](https://github.com/valkey-io/valkey-glide/blob/main/glide-core/src/protobuf/command_request.proto). Other language clients (Python, Java, Go) are the reference for semantics and routing.
|
|
270
|
+
|
|
271
|
+
### Steps
|
|
272
|
+
|
|
273
|
+
1. **Add `RequestType` constant** in `lib/valkey/request_type.rb` if not present (must match glide-core enum).
|
|
274
|
+
2. **Implement the command** in the appropriate file under `lib/valkey/commands/` (e.g. `string_commands.rb`, `hash_commands.rb`).
|
|
275
|
+
3. **Use `send_command`** with the correct `RequestType` and argument list (all arguments converted to strings for FFI).
|
|
276
|
+
4. **Add standalone tests** in `test/valkey/<group>_commands_test.rb`.
|
|
277
|
+
5. **Add lint tests** in `test/lint/<group>_commands.rb` when the command should match redis-rb behavior.
|
|
278
|
+
6. **Update the wiki** [command implementation status](https://github.com/valkey-io/valkey-glide-ruby/wiki/The-implementation-status-of-the-Valkey-commands).
|
|
279
|
+
|
|
280
|
+
### Command module layout
|
|
281
|
+
|
|
282
|
+
| Module file | Valkey command families |
|
|
283
|
+
|-------------|-------------------------|
|
|
284
|
+
| `string_commands.rb` | Strings, counters |
|
|
285
|
+
| `hash_commands.rb` | Hashes |
|
|
286
|
+
| `list_commands.rb` | Lists |
|
|
287
|
+
| `set_commands.rb` | Sets |
|
|
288
|
+
| `sorted_set_commands.rb` | Sorted sets |
|
|
289
|
+
| `stream_commands.rb` | Streams |
|
|
290
|
+
| `bitmap_commands.rb` | Bitmaps |
|
|
291
|
+
| `hyper_log_log_commands.rb` | HyperLogLog |
|
|
292
|
+
| `geo_commands.rb` | Geo |
|
|
293
|
+
| `generic_commands.rb` | Keys, scan, type, … |
|
|
294
|
+
| `connection_commands.rb` | Connection, auth, select |
|
|
295
|
+
| `server_commands.rb` | Server, config, ACL |
|
|
296
|
+
| `scripting_commands.rb` | Lua scripting |
|
|
297
|
+
| `function_commands.rb` | Functions |
|
|
298
|
+
| `transaction_commands.rb` | MULTI, WATCH, … |
|
|
299
|
+
| `pubsub_commands.rb` | Pub/Sub |
|
|
300
|
+
| `cluster_commands.rb` | Cluster administration |
|
|
301
|
+
| `json_commands.rb` | RedisJSON / Valkey JSON |
|
|
302
|
+
| `vector_search_commands.rb` | RediSearch / FT |
|
|
303
|
+
| `module_commands.rb` | MODULE |
|
|
304
|
+
|
|
305
|
+
### Tests
|
|
306
|
+
|
|
307
|
+
- **Unit-style command tests**: `test/valkey/*_test.rb` — require a running server.
|
|
308
|
+
- **Lint suites**: `test/lint/*.rb` — included from valkey and cluster tests for API parity checks.
|
|
309
|
+
- **OpenTelemetry**: `test/valkey/test_opentelemetry.rb` — uses file exporter endpoints.
|
|
310
|
+
- **Statistics**: `test/valkey/test_statistics.rb`.
|
|
311
|
+
|
|
312
|
+
### Documentation in code
|
|
313
|
+
|
|
314
|
+
Follow existing YARD-style comments in command modules: link to [valkey.io/commands](https://valkey.io/commands/), document parameters and return types, note cluster vs standalone behavior.
|
|
315
|
+
|
|
316
|
+
## OpenTelemetry Development
|
|
317
|
+
|
|
318
|
+
OpenTelemetry is configured via `Valkey::OpenTelemetry.init` before client creation. Sampling is applied in Ruby (`should_sample?`); spans are created in FFI (`create_otel_span`, `create_batch_otel_span`).
|
|
319
|
+
|
|
320
|
+
File exporter example for local debugging:
|
|
321
|
+
|
|
322
|
+
```ruby
|
|
323
|
+
Valkey::OpenTelemetry.init(
|
|
324
|
+
traces: { endpoint: "file:///tmp/valkey_traces.json", sample_percentage: 100 },
|
|
325
|
+
metrics: { endpoint: "file:///tmp/valkey_metrics.json" }
|
|
326
|
+
)
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Run OTel tests:
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
bundle exec ruby test/valkey/test_opentelemetry.rb
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## CI Overview
|
|
336
|
+
|
|
337
|
+
GitHub Actions (`.github/workflows/CI.yml`):
|
|
338
|
+
|
|
339
|
+
| Job | Matrix |
|
|
340
|
+
|-----|--------|
|
|
341
|
+
| `lint` | Ruby 3.3, RuboCop |
|
|
342
|
+
| `standalone` | Ruby 2.6–3.4 + JRuby; Valkey 7.2, 8, 8.1 |
|
|
343
|
+
| `cluster` | Ruby 2.6–3.4; grokzen/redis-cluster |
|
|
344
|
+
|
|
345
|
+
## Packaging
|
|
346
|
+
|
|
347
|
+
Release artifacts are built via `valkey.gemspec`:
|
|
348
|
+
|
|
349
|
+
- Native libraries under `lib/valkey/` are included in the gem.
|
|
350
|
+
- Test files, `bin/`, and `.github/` are excluded from the release.
|
|
351
|
+
|
|
352
|
+
Build locally:
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
gem build valkey.gemspec
|
|
356
|
+
gem install ./valkey-rb-*.gem
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## Troubleshooting
|
|
360
|
+
|
|
361
|
+
| Problem | Suggestion |
|
|
362
|
+
|---------|------------|
|
|
363
|
+
| `CannotConnectError` | Ensure Valkey is running on the configured host/port; cluster requires all seed nodes. |
|
|
364
|
+
| `LoadError` / FFI library not found | Confirm `lib/valkey/libglide_ffi.{so,dylib}` exists and matches your OS/arch. |
|
|
365
|
+
| Wrong architecture after FFI rebuild | Rebuild `glide-ffi` on the target platform; do not copy Linux `.so` to macOS. |
|
|
366
|
+
| Cluster tests flaky | Wait for `cluster_state:ok`; increase `TIMEOUT` env var. |
|
|
367
|
+
| SSL test failures | Regenerate certs: `ruby test/fixtures/ssl/generate_certs.rb`. |
|
|
368
|
+
| Pipeline / MULTI crashes | Transaction commands in `pipelined` use sequential fallback by design. |
|
|
369
|
+
|
|
370
|
+
## Recommended Editor Extensions
|
|
371
|
+
|
|
372
|
+
- [Ruby LSP](https://marketplace.visualstudio.com/items?itemName=Shopify.ruby-lsp) or [Solargraph](https://marketplace.visualstudio.com/items?itemName=castwide.solargraph)
|
|
373
|
+
- [RuboCop](https://marketplace.visualstudio.com/items?itemName=rubocop.vscode-rubocop)
|
|
374
|
+
- [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) — when editing valkey-glide FFI
|
|
375
|
+
|
|
376
|
+
## Examples
|
|
377
|
+
|
|
378
|
+
Sample scripts live in [examples/](./examples/). Run from the repo root:
|
|
379
|
+
|
|
380
|
+
```bash
|
|
381
|
+
bundle exec ruby examples/standalone.rb
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
See [examples/README.md](./examples/README.md) for Docker setup and environment variables.
|
|
385
|
+
|
|
386
|
+
## Community and Feedback
|
|
387
|
+
|
|
388
|
+
Join Valkey Slack: [Join Valkey Slack](https://join.slack.com/t/valkey-oss-developer/shared_invite/zt-2nxs51chx-EB9hu9Qdch3GMfRcztTSkQ).
|
|
389
|
+
|
|
390
|
+
Contribution guidelines: [CONTRIBUTING.md](./CONTRIBUTING.md). Broader GLIDE process: [valkey-glide CONTRIBUTING.md](https://github.com/valkey-io/valkey-glide/blob/main/CONTRIBUTING.md).
|
data/README.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# Valkey GLIDE for Ruby
|
|
2
|
+
|
|
3
|
+
Valkey General Language Independent Driver for the Enterprise (GLIDE) is the official open-source Valkey client library, proudly part of the [Valkey](https://valkey.io) organization. The Ruby gem (`valkey-rb`) wraps [Valkey GLIDE Core](https://github.com/valkey-io/valkey-glide) (Rust) and aims to be a **drop-in replacement for [redis-rb](https://github.com/redis/redis-rb)** while delivering GLIDE performance, reliability, and enterprise features.
|
|
4
|
+
|
|
5
|
+
## Why Choose Valkey GLIDE?
|
|
6
|
+
|
|
7
|
+
- **Community and Open Source**: Join our vibrant community and contribute to the project.
|
|
8
|
+
- **Reliability**: Built with best practices learned from over a decade of operating Redis OSS-compatible services.
|
|
9
|
+
- **Performance**: Optimized for high performance and low latency via the Rust-based GLIDE core.
|
|
10
|
+
- **High Availability**: Cluster-aware routing, reconnection, and fault tolerance.
|
|
11
|
+
- **Cross-Language Consistency**: Same core driver as Python, Java, Node.js, and Go clients.
|
|
12
|
+
- **Drop-in Replacement**: Familiar redis-rb-style API (`Valkey.new`, command methods, `pipelined`, URL parsing).
|
|
13
|
+
- **Observability**: Native OpenTelemetry tracing and client statistics.
|
|
14
|
+
|
|
15
|
+
## Documentation
|
|
16
|
+
|
|
17
|
+
- **Command coverage**: [Implementation status wiki](https://github.com/valkey-io/valkey-glide-ruby/wiki/The-implementation-status-of-the-Valkey-commands)
|
|
18
|
+
- **Valkey GLIDE overview**: [glide.valkey.io](https://glide.valkey.io/)
|
|
19
|
+
- **Supported engine versions**: [valkey-glide README — Supported Engine Versions](https://github.com/valkey-io/valkey-glide/blob/main/README.md#supported-engine-versions)
|
|
20
|
+
- **Local development**: [DEVELOPER.md](./DEVELOPER.md)
|
|
21
|
+
|
|
22
|
+
## Supported Engine Versions
|
|
23
|
+
|
|
24
|
+
| Engine Type | 6.2 | 7.0 | 7.1 | 7.2 | 8.0 | 8.1 | 9.0 |
|
|
25
|
+
|-------------|-----|-----|-----|-----|-----|-----|-----|
|
|
26
|
+
| Valkey | - | - | - | ✓ | ✓ | ✓ | ✓ |
|
|
27
|
+
| Redis OSS | ✓ | ✓ | ✓ | ✓ | - | - | - |
|
|
28
|
+
|
|
29
|
+
## Getting Started — Ruby Wrapper
|
|
30
|
+
|
|
31
|
+
### System Requirements
|
|
32
|
+
|
|
33
|
+
The release of Valkey GLIDE Ruby was tested on the following platforms:
|
|
34
|
+
|
|
35
|
+
**Linux:**
|
|
36
|
+
|
|
37
|
+
- Ubuntu 20+ (x86_64/amd64 and arm64/aarch64)
|
|
38
|
+
- Amazon Linux 2 (AL2) and 2023 (AL2023) (x86_64)
|
|
39
|
+
|
|
40
|
+
**Note:** Alpine Linux / MUSL is **not** currently supported.
|
|
41
|
+
|
|
42
|
+
**macOS:**
|
|
43
|
+
|
|
44
|
+
- macOS 14.7+ (Apple silicon / aarch64)
|
|
45
|
+
- macOS 13.7+ (x86_64 / amd64)
|
|
46
|
+
|
|
47
|
+
### Ruby Supported Versions
|
|
48
|
+
|
|
49
|
+
| Ruby Version | MRI | JRuby |
|
|
50
|
+
|--------------|-----|-------|
|
|
51
|
+
| 2.6 | ✓ | - |
|
|
52
|
+
| 2.7 | ✓ | - |
|
|
53
|
+
| 3.0 – 3.4 | ✓ | ✓ |
|
|
54
|
+
|
|
55
|
+
Minimum Ruby version: **2.6.0** (see `valkey.gemspec`).
|
|
56
|
+
|
|
57
|
+
### Installation and Setup
|
|
58
|
+
|
|
59
|
+
Install from RubyGems:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
gem install valkey-rb
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Or add to your `Gemfile`:
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
gem "valkey-rb"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Verify installation:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
ruby -e 'require "valkey"; puts Valkey::VERSION'
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The gem ships prebuilt native libraries (`libglide_ffi.so` on Linux, `libglide_ffi.dylib` on macOS) and depends on the [`ffi`](https://github.com/ffi/ffi) gem.
|
|
78
|
+
|
|
79
|
+
## Basic Examples
|
|
80
|
+
|
|
81
|
+
### Standalone Mode
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
require "valkey"
|
|
85
|
+
|
|
86
|
+
client = Valkey.new(host: "localhost", port: 6379)
|
|
87
|
+
|
|
88
|
+
client.set("mykey", "hello world")
|
|
89
|
+
# => "OK"
|
|
90
|
+
|
|
91
|
+
client.get("mykey")
|
|
92
|
+
# => "hello world"
|
|
93
|
+
|
|
94
|
+
client.close
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Standalone with URL (redis-rb compatible)
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
client = Valkey.new(url: "redis://localhost:6379/0")
|
|
101
|
+
# TLS: rediss://user:password@localhost:6380/0
|
|
102
|
+
|
|
103
|
+
client.ping
|
|
104
|
+
# => "PONG"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Cluster Mode
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
nodes = [
|
|
111
|
+
{ host: "127.0.0.1", port: 7000 },
|
|
112
|
+
{ host: "127.0.0.1", port: 7001 },
|
|
113
|
+
{ host: "127.0.0.1", port: 7002 },
|
|
114
|
+
{ host: "127.0.0.1", port: 7003 },
|
|
115
|
+
{ host: "127.0.0.1", port: 7004 },
|
|
116
|
+
{ host: "127.0.0.1", port: 7005 }
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
client = Valkey.new(nodes: nodes, cluster_mode: true)
|
|
120
|
+
client.set("foo", "bar")
|
|
121
|
+
client.get("foo")
|
|
122
|
+
# => "bar"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Pipelining
|
|
126
|
+
|
|
127
|
+
Batch multiple commands in a single network round trip (non-atomic pipeline):
|
|
128
|
+
|
|
129
|
+
```ruby
|
|
130
|
+
results = client.pipelined do |pipe|
|
|
131
|
+
pipe.set("key1", "value1")
|
|
132
|
+
pipe.get("key1")
|
|
133
|
+
pipe.incr("counter")
|
|
134
|
+
end
|
|
135
|
+
# => ["OK", "value1", 1]
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
> **Note:** Transactional commands (`MULTI` / `EXEC` / `DISCARD`) in a pipeline are executed sequentially as a workaround for FFI batch stability. Prefer `multi` / `exec` on the main client for transactions.
|
|
139
|
+
|
|
140
|
+
### Connection Options (redis-rb compatible)
|
|
141
|
+
|
|
142
|
+
| Option | Description |
|
|
143
|
+
|--------|-------------|
|
|
144
|
+
| `host`, `port` | Server address (default `127.0.0.1:6379`) |
|
|
145
|
+
| `url` | `redis://` or `rediss://` URI (merged with explicit options) |
|
|
146
|
+
| `db` | Database index (standalone only) |
|
|
147
|
+
| `password`, `username` | Authentication |
|
|
148
|
+
| `timeout` | Request timeout in seconds (default `5.0`) |
|
|
149
|
+
| `connect_timeout` | Connection timeout in seconds |
|
|
150
|
+
| `ssl`, `ssl_params` | TLS (`ca_file`, `cert`, `key`, `ca_path`, `root_certs`) |
|
|
151
|
+
| `cluster_mode` | Enable cluster client |
|
|
152
|
+
| `nodes` | Array of `{ host:, port: }` hashes |
|
|
153
|
+
| `protocol` | `:resp2` (default) or `:resp3` |
|
|
154
|
+
| `client_name` | `CLIENT SETNAME` value |
|
|
155
|
+
| `reconnect_attempts`, `reconnect_delay`, `reconnect_delay_max` | Connection retry strategy |
|
|
156
|
+
|
|
157
|
+
```ruby
|
|
158
|
+
client = Valkey.new(
|
|
159
|
+
host: "localhost",
|
|
160
|
+
port: 6379,
|
|
161
|
+
timeout: 2.0,
|
|
162
|
+
connect_timeout: 1.0,
|
|
163
|
+
client_name: "my-app",
|
|
164
|
+
protocol: :resp3
|
|
165
|
+
)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## OpenTelemetry
|
|
169
|
+
|
|
170
|
+
Valkey GLIDE Ruby configures OpenTelemetry in the **native Rust core** (not via the Ruby `opentelemetry-sdk` gem). Initialize once per process before creating clients:
|
|
171
|
+
|
|
172
|
+
```ruby
|
|
173
|
+
require "valkey"
|
|
174
|
+
|
|
175
|
+
Valkey::OpenTelemetry.init(
|
|
176
|
+
traces: {
|
|
177
|
+
endpoint: "http://localhost:4318/v1/traces",
|
|
178
|
+
sample_percentage: 10
|
|
179
|
+
},
|
|
180
|
+
metrics: {
|
|
181
|
+
endpoint: "http://localhost:4318/v1/metrics"
|
|
182
|
+
},
|
|
183
|
+
flush_interval_ms: 5000
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
client = Valkey.new(host: "localhost", port: 6379)
|
|
187
|
+
client.set("key", "value") # traced when sampling applies
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**Supported endpoint formats:**
|
|
191
|
+
|
|
192
|
+
- HTTP/HTTPS: `http://localhost:4318/v1/traces`
|
|
193
|
+
- gRPC: `grpc://localhost:4317`
|
|
194
|
+
- File (testing): `file:///tmp/valkey_traces.json`
|
|
195
|
+
|
|
196
|
+
OpenTelemetry can only be initialized **once per process**. Spans are created in the FFI layer when sampling is enabled.
|
|
197
|
+
|
|
198
|
+
## Examples
|
|
199
|
+
|
|
200
|
+
Runnable examples are in [examples/](./examples/):
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
bundle exec ruby examples/standalone.rb
|
|
204
|
+
bundle exec ruby examples/pipelining.rb
|
|
205
|
+
bundle exec ruby examples/opentelemetry.rb
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
See [examples/README.md](./examples/README.md) for cluster setup and environment variables.
|
|
209
|
+
|
|
210
|
+
## Client Statistics
|
|
211
|
+
|
|
212
|
+
Monitor global client metrics (shared across all clients in the process):
|
|
213
|
+
|
|
214
|
+
```ruby
|
|
215
|
+
stats = client.get_statistics
|
|
216
|
+
# alias: client.statistics
|
|
217
|
+
|
|
218
|
+
puts "Connections: #{stats[:total_connections]}"
|
|
219
|
+
puts "Clients: #{stats[:total_clients]}"
|
|
220
|
+
puts "Compressed values: #{stats[:total_values_compressed]}"
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Available keys: `:total_connections`, `:total_clients`, `:total_values_compressed`, `:total_values_decompressed`, `:total_original_bytes`, `:total_bytes_compressed`, `:total_bytes_decompressed`, `:compression_skipped_count`.
|
|
224
|
+
|
|
225
|
+
## Pub/Sub
|
|
226
|
+
|
|
227
|
+
Pub/Sub uses a native callback registered at connection time. Configure subscriptions via command modules (`subscribe`, `psubscribe`, etc.). See [DEVELOPER.md](./DEVELOPER.md) and integration tests in `test/valkey/pubsub_commands_test.rb` for details.
|
|
228
|
+
|
|
229
|
+
## Layout of Ruby Code
|
|
230
|
+
|
|
231
|
+
| Path | Purpose |
|
|
232
|
+
|------|---------|
|
|
233
|
+
| `lib/valkey.rb` | Main client: connection, pipelining, response conversion |
|
|
234
|
+
| `lib/valkey/bindings.rb` | FFI bindings to `libglide_ffi` |
|
|
235
|
+
| `lib/valkey/commands/` | Command modules (strings, hashes, streams, cluster, JSON, vector search, …) |
|
|
236
|
+
| `lib/valkey/opentelemetry.rb` | OpenTelemetry configuration |
|
|
237
|
+
| `lib/valkey/pipeline.rb` | Pipeline command batching |
|
|
238
|
+
| `test/valkey/` | Standalone integration tests |
|
|
239
|
+
| `test/cluster/` | Cluster integration tests |
|
|
240
|
+
| `test/lint/` | Shared lint tests (redis-rb compatibility patterns) |
|
|
241
|
+
|
|
242
|
+
## redis-rb Compatibility
|
|
243
|
+
|
|
244
|
+
This client mirrors redis-rb conventions where possible:
|
|
245
|
+
|
|
246
|
+
- `Valkey.new` with `url`, `host`, `port`, `db`, `ssl_params`
|
|
247
|
+
- Command method names and argument ordering aligned with redis-rb
|
|
248
|
+
- `pipelined`, `multi` / `exec`, `disconnect!` (alias of `close`)
|
|
249
|
+
|
|
250
|
+
Not every redis-rb API is implemented yet. See the [command implementation wiki](https://github.com/valkey-io/valkey-glide-ruby/wiki/The-implementation-status-of-the-Valkey-commands) for coverage.
|
|
251
|
+
|
|
252
|
+
## Building and Testing
|
|
253
|
+
|
|
254
|
+
Instructions for building from source, updating the FFI library, running tests, and contributing are in [DEVELOPER.md](./DEVELOPER.md).
|
|
255
|
+
|
|
256
|
+
For AI-assisted development, see [AGENTS.md](./AGENTS.md) and [CLAUDE.md](./CLAUDE.md).
|
|
257
|
+
|
|
258
|
+
Contributing: [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
259
|
+
|
|
260
|
+
## Community and Feedback
|
|
261
|
+
|
|
262
|
+
We encourage you to join our community to support, share feedback, and ask questions on Valkey Slack: [Join Valkey Slack](https://join.slack.com/t/valkey-oss-developer/shared_invite/zt-2nxs51chx-EB9hu9Qdch3GMfRcztTSkQ).
|
|
263
|
+
|
|
264
|
+
Report issues: [valkey-glide-ruby issues](https://github.com/valkey-io/valkey-glide-ruby/issues).
|
|
265
|
+
|
|
266
|
+
## License
|
|
267
|
+
|
|
268
|
+
Apache-2.0 — see [LICENSE](https://github.com/valkey-io/valkey-glide-ruby/blob/main/LICENSE) in the repository.
|