Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c3fd3ca
core string ops
alii Sep 30, 2025
9a56a30
feat: Implement key management commands
alii Sep 30, 2025
e9731b2
feat: Implement expire commands
alii Sep 30, 2025
6ce6a1a
feat: Implement the most simple sorted set commands
alii Sep 30, 2025
bae58b9
feat: Implement zmscore/zrem
alii Sep 30, 2025
781e57a
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 30, 2025
1d46d3f
update zrem & zmscore
alii Sep 30, 2025
02b051f
zrange/zrevrange/zrangebyscore/zrevrangebyscore/zrangebylex/zrevrange…
alii Sep 30, 2025
5c127c7
Merge branch 'ali/redis' of github.com:oven-sh/bun into ali/redis
alii Sep 30, 2025
17f43fd
rm
alii Sep 30, 2025
3694529
feat: Implement some more set operations
alii Sep 30, 2025
8ca3c8c
impl blocking zmpop/bzmpop/bzmpopmin/bzmpopmax
alii Sep 30, 2025
f7ea775
feat: Implement Redis list operations
alii Sep 30, 2025
47f906a
feat: add all the remaining set operations
alii Sep 30, 2025
1811057
remove duplicated set operations
alii Sep 30, 2025
413ed55
deprecated RedisClient#hmset
alii Sep 30, 2025
f3bd6e6
hset/hmset types
alii Sep 30, 2025
859e94d
hset/hmset tests
alii Sep 30, 2025
8ceffca
hmset/hset impl
alii Sep 30, 2025
68f96de
types for hdel, hexists, hrandfield, hscan
alii Sep 30, 2025
eee5b3e
feat: impl hdel,hexists,hrandfield,hscan
alii Sep 30, 2025
b17268e
fix hrandfield failing test
alii Sep 30, 2025
1ccee32
feat: impl hsetnx
alii Sep 30, 2025
17e5861
hgetdel/hgetex/hsetex
alii Sep 30, 2025
7e8b5f3
test with redis 8
alii Sep 30, 2025
4cc0018
feat: Implement HGETDEL, HGETEX, HSETEX, HEXPIRE, HEXPIREAT, HEXPIRET…
alii Sep 30, 2025
f48dd34
accident
alii Sep 30, 2025
02fb857
ci: fix redis image/compose
alii Sep 30, 2025
177d384
fix: hpexpire should come after key exists
alii Sep 30, 2025
56c3f1f
feat: add expectation for hpexpire result
alii Sep 30, 2025
2afb2c2
rm
alii Sep 30, 2025
4c976cb
address the primary coderabbit feedback
alii Sep 30, 2025
5de2c78
use fixed arity for some fns
alii Sep 30, 2025
e6b9e56
update some missing types
alii Sep 30, 2025
2503614
update variadic methods
alii Sep 30, 2025
62e0eda
update sorted set types
alii Sep 30, 2025
53cd46c
a bunch more coverage
alii Sep 30, 2025
1e16e7e
fix: hmget is variadic
alii Sep 30, 2025
ec3d7c2
deflake
alii Sep 30, 2025
fd0b807
update types
alii Sep 30, 2025
9c57e0b
rm
alii Sep 30, 2025
c9fa18b
tests for hmget(key, string_arr)
alii Sep 30, 2025
e65fbc3
fix: support hmget with an array of fields as the second arg
alii Sep 30, 2025
7e18d04
srandmember has no withscores (not sorted set)
alii Sep 30, 2025
eeddcd4
expect error for invalid args
alii Sep 30, 2025
b2bced7
Fix some return types
alii Sep 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions packages/bun-types/redis.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,37 @@ declare module "bun" {
*/
incr(key: RedisClient.KeyLike): Promise<number>;

/**
* Increment the integer value of a key by the given amount
* @param key The key to increment
* @param increment The amount to increment by
* @returns Promise that resolves with the new value after incrementing
*/
incrby(key: RedisClient.KeyLike, increment: number): Promise<number>;

/**
* Increment the float value of a key by the given amount
* @param key The key to increment
* @param increment The amount to increment by (can be a float)
* @returns Promise that resolves with the new value as a string after incrementing
*/
incrbyfloat(key: RedisClient.KeyLike, increment: number | string): Promise<string>;

/**
* Decrement the integer value of a key by one
* @param key The key to decrement
* @returns Promise that resolves with the new value
*/
decr(key: RedisClient.KeyLike): Promise<number>;

/**
* Decrement the integer value of a key by the given amount
* @param key The key to decrement
* @param decrement The amount to decrement by
* @returns Promise that resolves with the new value after decrementing
*/
decrby(key: RedisClient.KeyLike, decrement: number): Promise<number>;

/**
* Determine if a key exists
* @param key The key to check
Expand Down Expand Up @@ -569,6 +593,36 @@ declare module "bun" {
*/
setnx(key: RedisClient.KeyLike, value: RedisClient.KeyLike): Promise<number>;

/**
* Set key to hold the string value with expiration time in seconds
* @param key The key to set
* @param seconds The expiration time in seconds
* @param value The value to set
* @returns Promise that resolves with "OK" on success
*
* @example
* ```ts
* await redis.setex("mykey", 10, "Hello");
* // Key will expire after 10 seconds
* ```
*/
setex(key: RedisClient.KeyLike, seconds: number, value: RedisClient.KeyLike): Promise<"OK">;

/**
* Set key to hold the string value with expiration time in milliseconds
* @param key The key to set
* @param milliseconds The expiration time in milliseconds
* @param value The value to set
* @returns Promise that resolves with "OK" on success
*
* @example
* ```ts
* await redis.psetex("mykey", 10000, "Hello");
* // Key will expire after 10000 milliseconds (10 seconds)
* ```
*/
psetex(key: RedisClient.KeyLike, milliseconds: number, value: RedisClient.KeyLike): Promise<"OK">;

/**
* Get the score associated with the given member in a sorted set
* @param key The sorted set key
Expand All @@ -586,13 +640,97 @@ declare module "bun" {
*/
mget(...keys: RedisClient.KeyLike[]): Promise<(string | null)[]>;

/**
* Set multiple keys to multiple values atomically
*
* Sets the given keys to their respective values. MSET replaces existing
* values with new values, just as regular SET. Use MSETNX if you don't want
* to overwrite existing values.
*
* MSET is atomic, so all given keys are set at once. It is not possible for
* clients to see that some of the keys were updated while others are
* unchanged.
*
* @param keyValuePairs Alternating keys and values (key1, value1, key2, value2, ...)
* @returns Promise that resolves with "OK" on success
*
* @example
* ```ts
* await redis.mset("key1", "value1", "key2", "value2");
* ```
*/
mset(...keyValuePairs: RedisClient.KeyLike[]): Promise<"OK">;

/**
* Set multiple keys to multiple values, only if none of the keys exist
*
* Sets the given keys to their respective values. MSETNX will not perform
* any operation at all even if just a single key already exists.
*
* Because of this semantic, MSETNX can be used in order to set different
* keys representing different fields of a unique logic object in a way that
* ensures that either all the fields or none at all are set.
*
* MSETNX is atomic, so all given keys are set at once. It is not possible
* for clients to see that some of the keys were updated while others are
* unchanged.
*
* @param keyValuePairs Alternating keys and values (key1, value1, key2, value2, ...)
* @returns Promise that resolves with 1 if all keys were set, 0 if no key was set
*
* @example
* ```ts
* // Returns 1 if keys don't exist
* await redis.msetnx("key1", "value1", "key2", "value2");
*
* // Returns 0 if any key already exists
* await redis.msetnx("key1", "newvalue", "key3", "value3");
* ```
*/
msetnx(...keyValuePairs: RedisClient.KeyLike[]): Promise<number>;

/**
* Count the number of set bits (population counting) in a string
* @param key The key to count bits in
* @returns Promise that resolves with the number of bits set to 1
*/
bitcount(key: RedisClient.KeyLike): Promise<number>;

/**
* Returns the bit value at offset in the string value stored at key
* @param key The key containing the string value
* @param offset The bit offset (zero-based)
* @returns Promise that resolves with the bit value (0 or 1) at the specified offset
*/
getbit(key: RedisClient.KeyLike, offset: number): Promise<number>;

/**
* Sets or clears the bit at offset in the string value stored at key
* @param key The key to modify
* @param offset The bit offset (zero-based)
* @param value The bit value to set (0 or 1)
* @returns Promise that resolves with the original bit value stored at offset
*/
setbit(key: RedisClient.KeyLike, offset: number, value: 0 | 1): Promise<number>;

/**
* Get a substring of the string stored at a key
* @param key The key to get the substring from
* @param start The starting offset (can be negative to count from the end)
* @param end The ending offset (can be negative to count from the end)
* @returns Promise that resolves with the substring, or an empty string if the key doesn't exist
*/
getrange(key: RedisClient.KeyLike, start: number, end: number): Promise<string>;

/**
* Overwrite part of a string at key starting at the specified offset
* @param key The key to modify
* @param offset The offset at which to start overwriting (zero-based)
* @param value The string value to write at the offset
* @returns Promise that resolves with the length of the string after modification
*/
setrange(key: RedisClient.KeyLike, offset: number, value: RedisClient.KeyLike): Promise<number>;

/**
* Return a serialized version of the value stored at the specified key
* @param key The key to dump
Expand Down
36 changes: 36 additions & 0 deletions src/bun.js/api/valkey.classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,22 @@ export default [
fn: "incr",
length: 1,
},
incrby: {
fn: "incrby",
length: 2,
},
incrbyfloat: {
fn: "incrbyfloat",
length: 2,
},
decr: {
fn: "decr",
length: 1,
},
decrby: {
fn: "decrby",
length: 2,
},
exists: {
fn: "exists",
length: 1,
Expand Down Expand Up @@ -123,6 +135,18 @@ export default [
bitcount: {
fn: "bitcount",
},
getbit: {
fn: "getbit",
},
setbit: {
fn: "setbit",
},
getrange: {
fn: "getrange",
},
setrange: {
fn: "setrange",
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
dump: {
fn: "dump",
},
Expand Down Expand Up @@ -210,12 +234,24 @@ export default [
setnx: {
fn: "setnx",
},
setex: {
fn: "setex",
},
psetex: {
fn: "psetex",
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
zscore: {
fn: "zscore",
},
mget: {
fn: "mget",
},
mset: {
fn: "mset",
},
msetnx: {
fn: "msetnx",
},
ping: { fn: "ping" },
publish: { fn: "publish" },
script: { fn: "script" },
Expand Down
11 changes: 11 additions & 0 deletions src/valkey/js_valkey_functions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ pub fn ping(this: *JSValkeyClient, globalObject: *jsc.JSGlobalObject, callframe:
}

pub const bitcount = compile.@"(key: RedisKey)"("bitcount", "BITCOUNT", "key", .not_subscriber).call;
pub const getbit = compile.@"(key: RedisKey, value: RedisValue)"("getbit", "GETBIT", "key", "offset", .not_subscriber).call;
pub const setbit = compile.@"(...strings: string[])"("setbit", "SETBIT", .not_subscriber).call;
pub const getrange = compile.@"(...strings: string[])"("getrange", "GETRANGE", .not_subscriber).call;
pub const setrange = compile.@"(...strings: string[])"("setrange", "SETRANGE", .not_subscriber).call;
pub const dump = compile.@"(key: RedisKey)"("dump", "DUMP", "key", .not_subscriber).call;
pub const expiretime = compile.@"(key: RedisKey)"("expiretime", "EXPIRETIME", "key", .not_subscriber).call;
pub const getdel = compile.@"(key: RedisKey)"("getdel", "GETDEL", "key", .not_subscriber).call;
Expand All @@ -657,16 +661,23 @@ pub const zrandmember = compile.@"(key: RedisKey)"("zrandmember", "ZRANDMEMBER",
pub const append = compile.@"(key: RedisKey, value: RedisValue)"("append", "APPEND", "key", "value", .not_subscriber).call;
pub const getset = compile.@"(key: RedisKey, value: RedisValue)"("getset", "GETSET", "key", "value", .not_subscriber).call;
pub const hget = compile.@"(key: RedisKey, value: RedisValue)"("hget", "HGET", "key", "field", .not_subscriber).call;
pub const incrby = compile.@"(key: RedisKey, value: RedisValue)"("incrby", "INCRBY", "key", "increment", .not_subscriber).call;
pub const incrbyfloat = compile.@"(key: RedisKey, value: RedisValue)"("incrbyfloat", "INCRBYFLOAT", "key", "increment", .not_subscriber).call;
pub const decrby = compile.@"(key: RedisKey, value: RedisValue)"("decrby", "DECRBY", "key", "decrement", .not_subscriber).call;
pub const lpush = compile.@"(key: RedisKey, value: RedisValue, ...args: RedisValue)"("lpush", "LPUSH", .not_subscriber).call;
pub const lpushx = compile.@"(key: RedisKey, value: RedisValue, ...args: RedisValue)"("lpushx", "LPUSHX", .not_subscriber).call;
pub const pfadd = compile.@"(key: RedisKey, value: RedisValue)"("pfadd", "PFADD", "key", "value", .not_subscriber).call;
pub const rpush = compile.@"(key: RedisKey, value: RedisValue, ...args: RedisValue)"("rpush", "RPUSH", .not_subscriber).call;
pub const rpushx = compile.@"(key: RedisKey, value: RedisValue, ...args: RedisValue)"("rpushx", "RPUSHX", .not_subscriber).call;
pub const setnx = compile.@"(key: RedisKey, value: RedisValue)"("setnx", "SETNX", "key", "value", .not_subscriber).call;
pub const setex = compile.@"(...strings: string[])"("setex", "SETEX", .not_subscriber).call;
pub const psetex = compile.@"(...strings: string[])"("psetex", "PSETEX", .not_subscriber).call;
pub const zscore = compile.@"(key: RedisKey, value: RedisValue)"("zscore", "ZSCORE", "key", "value", .not_subscriber).call;

pub const del = compile.@"(key: RedisKey, ...args: RedisKey[])"("del", "DEL", "key", .not_subscriber).call;
pub const mget = compile.@"(key: RedisKey, ...args: RedisKey[])"("mget", "MGET", "key", .not_subscriber).call;
pub const mset = compile.@"(...strings: string[])"("mset", "MSET", .not_subscriber).call;
pub const msetnx = compile.@"(...strings: string[])"("msetnx", "MSETNX", .not_subscriber).call;

pub const script = compile.@"(...strings: string[])"("script", "SCRIPT", .not_subscriber).call;
pub const select = compile.@"(...strings: string[])"("select", "SELECT", .not_subscriber).call;
Expand Down
Loading