Bun v1.2.9 已发布,此版本修复了 48 个 bug,其他变化包括:
- Bun 现在内置了 Redis 客户端
Bun.redis
Bun.S3Client
中的ListObjectsV2
支持- 更多的
libuv
符号 require.extensions
兼容性
公告写道,Bun 现在内置了一个速度非常快的 Redis/Valkey 客户端——采用 Zig 从头开始编写。
import { redis, RedisClient } from "bun";
// Reads $REDIS_URL from environment
await redis.set("foo", "bar");
const value = await redis.get("foo");
console.log(value); // "bar"
await redis.ttl("foo"); // 10 seconds
// or use redis.set("foo", "bar", "EX", 10)
const custom = new RedisClient("redis://localhost:6379", {
// options
});
await custom.set("foo", "bar");
性能表现:
❯ bun-latest redis.mjs
[146.08ms] Bun.redis GET 'greeting' 10000 batches of 10
[211.52ms] ioredis GET 'greeting' 10000 batches of 10
→ Bun.redis is 44.82% faster
[527.04ms] Bun.redis GET 'greeting' 10000 batches of 100
[834.25ms] ioredis GET 'greeting' 10000 batches of 100
→ Bun.redis is 58.29% faster
[4.22s] Bun.redis GET 'greeting' 10000 batches of 1000
[7.83s] ioredis GET 'greeting' 10000 batches of 1000
→ Bun.redis is 85.39% faster
❯ node redis.mjs
ioredis GET 'greeting' 10000 batches of 10: 270.837ms
ioredis GET 'greeting' 10000 batches of 100: 1.181s
ioredis GET 'greeting' 10000 batches of 1000: 10.095s