Squirix speaks a second language

Alexander Efremov · · Architecture

Squirix 0.2.0 is the first stable release in the 0.2 series. The packages are available on NuGet, and the server now speaks both RESP2 and RESP3. If you already use StackExchange.Redis for caching, you can keep your .NET client and point it at Squirix. Other Redis clients, including redis-cli, can use the same endpoint for the commands listed below.

Cache a product name with StackExchange.Redis

Start a local node with squirix-server run and add the StackExchange.Redis NuGet package to your .NET project. Here’s how to cache a product name for five minutes and read it back:

using StackExchange.Redis;

using var redis = await ConnectionMultiplexer.ConnectAsync("127.0.0.1:6379");
var cache = redis.GetDatabase(0);
await cache.StringSetAsync("product:42", "Coffee grinder", TimeSpan.FromMinutes(5));
string? name = await cache.StringGetAsync("product:42");
Console.WriteLine(name); // Coffee grinder

Squirix maps database 0 to the cache named resp. In a cluster, Squirix routes the key to its owner and applies the usual replication policy to writes.

Supported RESP commands

  • GET, EXISTS, DEL, UNLINK
  • SET (optional expiry EX or PX, optional condition NX or XX), SETNX, SETEX, PSETEX
  • EXPIRE, PEXPIRE, TTL, PTTL, PERSIST
  • PING, ECHO, AUTH, HELLO 2, HELLO 3, SELECT 0
  • INFO, CLIENT ID, CLIENT GETNAME, CLIENT SETNAME, CLIENT SETINFO

Configuring the listener in appsettings.json

The server and native SDK now read settings from appsettings.json. If another service already uses port 6379, put this file in the server’s working directory and restart Squirix. Then connect to 127.0.0.1:6380. You can also override the port with SQUIRIX_RESP_PORT.

{
  "Squirix": {
    "Resp": {
      "BindAddress": "127.0.0.1",
      "Port": 6380
    }
  }
}

If you’re upgrading from preview.1, move the Squirix section from Squirix.settings.json into the new file and update any Docker mounts that name it.

Reading from Squirix and Garnet with the same client

After 0.2.0-preview.1, I started comparing Squirix with Garnet under pipelined reads. RESP let me use the same StackExchange.Redis client for both. Garnet handled more reads per second on busy connections, which led me to look at how Squirix sends replies.

When several commands are already buffered on a RESP connection, Squirix can write their replies together in request order. A lone command gets its reply as soon as it’s ready. I also changed the server’s native binary writer. It can now encode up to sixteen ready replies in one output segment.

For the comparison below, the client used RESP2 on both servers. It checked for a miss, then stored a different 4 KiB string under each of 8,192 keys. The timed portion consisted entirely of cache hits. The client called StringGetAsync and checked the full value on every read.

Depth 1 means each connection waited for a reply before sending another read. At depth 16 it issued sixteen reads together. Batch p99 measures the time from issuing the first read to verifying the last reply in that batch.

Measurement Pipeline depth Squirix 0.2.0 Garnet 2.2.14
Reads/s 1 122,819 125,676
Server CPU (µs/read) 1 15.14 14.84
Batch p99 (ms) 1 0.37 0.36
Reads/s 16 457,181 578,439
Server CPU (µs/read) 16 3.90 2.32
Batch p99 (ms) 16 1.58 2.96

At depth 1, Squirix served about 2% fewer reads per second than Garnet. At depth 16 the gap widened to 21%, and Squirix used more server CPU per read. At that depth its batch p99 was lower (1.58 ms versus 2.96 ms).

I ran the benchmark on Windows with a Core Ultra 9 285K, .NET 10.0.15 and StackExchange.Redis 3.4.0. Each run started a fresh server and used loopback TCP, with two logical CPUs for the server and six others for the client. Across sixteen connections, the client completed 262,144 warm-up reads followed by 524,288 measured reads. Each table entry is the median of five runs. Squirix benchmark workloads and results

Defaults to check when upgrading from preview.1

  • Client TLS is opt-in. The binary and RESP listeners use plain TCP by default. To enable encryption, configure a server certificate that your client trusts and start squirix-server run --tls. In StackExchange.Redis, set Ssl = true. Remote cluster peers still require mutual TLS. Squirix listener settings
  • Background expiry cleanup is opt-in. Reads still treat expired keys as missing. To reclaim expired keys that nobody reads again, set Squirix:Cluster:ExpirationSweepIntervalMilliseconds to a positive interval in appsettings.json. The default, -1, disables the sweep. A value of 1000 schedules one pass per second. The standalone host has no dedicated CLI flag for this interval.
  • Cache memory accounting is opt-in. Enable it if you use memory-based eviction or limit writes under memory pressure. Use --memory-accounting, set Squirix:MemoryPressure:memoryAccountingEnabled to true in JSON, or set SQUIRIX_MEMORY_PRESSURE_ACCOUNTING_ENABLED=true. Key-count eviction works independently. Configuration reference
  • Persistent nodes group journal writes. Set the wait in appsettings.json with Squirix:Cluster:Journal:GroupCommitMaxWait. It defaults to 00:00:00.002 (2 ms) and has no dedicated CLI flag. Concurrent writes can share a flush, while an isolated write can wait the full window. Set it to zero to make pending writes eligible for an immediate flush. Journal settings

Back to the blog

Comments