Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/redis/mod.ts>RedisCommands

๐Ÿฆ• Redis client for Deno ๐Ÿ•
Very Popular
Latest
interface RedisCommands
import { type RedisCommands } from "https://deno.land/x/redis@v0.32.3/mod.ts";

Methods

auth(password: string): Promise<SimpleString>
auth(username: string, password: string): Promise<SimpleString>
echo(message: RedisValue): Promise<BulkString>
ping(): Promise<SimpleString>
ping(message: RedisValue): Promise<BulkString>
quit(): Promise<SimpleString>
select(index: number): Promise<SimpleString>
del(...keys: string[]): Promise<Integer>
dump(key: string): Promise<Binary | BulkNil>
exists(...keys: string[]): Promise<Integer>
expire(key: string, seconds: number): Promise<Integer>
expireat(key: string, timestamp: string): Promise<Integer>
keys(pattern: string): Promise<BulkString[]>
migrate(
host: string,
port: number | string,
key: string,
destination_db: string,
timeout: number,
opts?: MigrateOpts,
): Promise<SimpleString>
move(key: string, db: string): Promise<Integer>
objectRefCount(key: string): Promise<Integer | BulkNil>
objectEncoding(key: string): Promise<Bulk>
objectIdletime(key: string): Promise<Integer | BulkNil>
objectFreq(key: string): Promise<Integer | BulkNil>
objectHelp(): Promise<BulkString[]>
persist(key: string): Promise<Integer>
pexpire(key: string, milliseconds: number): Promise<Integer>
pexpireat(key: string, milliseconds_timestamp: number): Promise<Integer>
pttl(key: string): Promise<Integer>
randomkey(): Promise<Bulk>
rename(key: string, newkey: string): Promise<SimpleString>
renamenx(key: string, newkey: string): Promise<Integer>
restore(
key: string,
ttl: number,
serialized_value: Binary,
opts?: RestoreOpts,
): Promise<SimpleString>
scan(cursor: number, opts?: ScanOpts): Promise<[BulkString, BulkString[]]>
sort(key: string, opts?: SortOpts): Promise<BulkString[]>
sort(key: string, opts?: SortWithDestinationOpts): Promise<Integer>
touch(...keys: string[]): Promise<Integer>
ttl(key: string): Promise<Integer>
type(key: string): Promise<SimpleString>
wait(numreplicas: number, timeout: number): Promise<Integer>
append(key: string, value: RedisValue): Promise<Integer>
bitcount(key: string): Promise<Integer>
bitcount(
key: string,
start: number,
end: number,
): Promise<Integer>
bitfield(key: string, opts?: BitfieldOpts): Promise<Integer[]>
bitfield(key: string, opts?: BitfieldWithOverflowOpts): Promise<(Integer | BulkNil)[]>
bitop(
operation: BitopOperation,
destkey: string,
...keys: string[],
): Promise<Integer>
bitpos(
key: string,
bit: number,
start?: number,
end?: number,
): Promise<Integer>
decr(key: string): Promise<Integer>
decrby(key: string, decrement: number): Promise<Integer>
get(key: string): Promise<Bulk>
getbit(key: string, offset: number): Promise<Integer>
getrange(
key: string,
start: number,
end: number,
): Promise<BulkString>
getset(key: string, value: RedisValue): Promise<Bulk>
incr(key: string): Promise<Integer>
incrby(key: string, increment: number): Promise<Integer>
incrbyfloat(key: string, increment: number): Promise<BulkString>
mget(...keys: string[]): Promise<Bulk[]>
mset(key: string, value: RedisValue): Promise<SimpleString>
mset(...key_values: [string, RedisValue][]): Promise<SimpleString>
mset(key_values: Record<string, RedisValue>): Promise<SimpleString>
msetnx(key: string, value: RedisValue): Promise<Integer>
msetnx(...key_values: [string, RedisValue][]): Promise<Integer>
msetnx(key_values: Record<string, RedisValue>): Promise<Integer>
psetex(
key: string,
milliseconds: number,
value: RedisValue,
): Promise<SimpleString>
set(
key: string,
value: RedisValue,
opts?: SetOpts,
): Promise<SimpleString>
set(
key: string,
value: RedisValue,
): Promise<SimpleString | BulkNil>
setbit(
key: string,
offset: number,
value: RedisValue,
): Promise<Integer>
setex(
key: string,
seconds: number,
value: RedisValue,
): Promise<SimpleString>
setnx(key: string, value: RedisValue): Promise<Integer>
setrange(
key: string,
offset: number,
value: RedisValue,
): Promise<Integer>
stralgo(
algorithm: StralgoAlgorithm,
target: StralgoTarget,
a: string,
b: string,
): Promise<Bulk>
stralgo(
algorithm: StralgoAlgorithm,
target: StralgoTarget,
a: string,
b: string,
opts?: { len: true; },
): Promise<Integer>
stralgo(
algorithm: StralgoAlgorithm,
target: StralgoTarget,
a: string,
b: string,
opts?: { idx: true; },
): Promise<
[
string,
Array<[[number, number], [number, number]]>,
string,
]
>
stralgo(
algorithm: StralgoAlgorithm,
target: StralgoTarget,
a: string,
b: string,
opts?: { idx: true; withmatchlen: true; },
): Promise<
[
string,
Array<[[number, number], [number, number], number]>,
string,
]
>
stralgo(
algorithm: StralgoAlgorithm,
target: StralgoTarget,
a: string,
b: string,
opts?: StralgoOpts,
): Promise<Bulk | Integer |
[
string,
Array<[[number, number], [number, number], number | undefined]>,
string,
]
>
strlen(key: string): Promise<Integer>
geoadd(
key: string,
longitude: number,
latitude: number,
member: string,
): Promise<Integer>
geoadd(key: string, ...lng_lat_members: [number, number, string][]): Promise<Integer>
geoadd(key: string, member_lng_lats: Record<string, [number, number]>): Promise<Integer>
geohash(key: string, ...members: string[]): Promise<Bulk[]>
geopos(key: string, ...members: string[]): Promise<Array<[BulkString, BulkString] | BulkNil | []> | BulkNil>
geodist(
key: string,
member1: string,
member2: string,
unit?:
| "m"
| "km"
| "ft"
| "mi"
,
): Promise<Bulk>
georadius(
key: string,
longitude: number,
latitude: number,
radius: number,
unit: GeoUnit,
): Promise<ConditionalArray>
georadiusbymember(
key: string,
member: string,
radius: number,
unit: GeoUnit,
): Promise<ConditionalArray>
hdel(key: string, ...fields: string[]): Promise<Integer>
hexists(key: string, field: string): Promise<Integer>
hget(key: string, field: string): Promise<Bulk>
hgetall(key: string): Promise<BulkString[]>
hincrby(
key: string,
field: string,
increment: number,
): Promise<Integer>
hincrbyfloat(
key: string,
field: string,
increment: number,
): Promise<BulkString>
hkeys(key: string): Promise<BulkString[]>
hlen(key: string): Promise<Integer>
hmget(key: string, ...fields: string[]): Promise<Bulk[]>
deprecated
hmset(
key: string,
field: string,
value: RedisValue,
): Promise<SimpleString>
deprecated
hmset(key: string, ...field_values: [string, RedisValue][]): Promise<SimpleString>
deprecated
hmset(key: string, field_values: Record<string, RedisValue>): Promise<SimpleString>
hscan(
key: string,
cursor: number,
opts?: HScanOpts,
): Promise<[BulkString, BulkString[]]>
hset(
key: string,
field: string,
value: RedisValue,
): Promise<Integer>
hset(key: string, ...fieldValues: [string, RedisValue][]): Promise<Integer>
hset(key: string, fieldValues: Record<string, RedisValue>): Promise<Integer>
hsetnx(
key: string,
field: string,
value: RedisValue,
): Promise<Integer>
hstrlen(key: string, field: string): Promise<Integer>
hvals(key: string): Promise<BulkString[]>
blpop(timeout: number, ...keys: string[]): Promise<[BulkString, BulkString] | BulkNil>
brpop(timeout: number, ...keys: string[]): Promise<[BulkString, BulkString] | BulkNil>
brpoplpush(
source: string,
destination: string,
timeout: number,
): Promise<Bulk>
lindex(key: string, index: number): Promise<Bulk>
linsert(
key: string,
pivot: string,
value: RedisValue,
): Promise<Integer>
llen(key: string): Promise<Integer>
lpop(key: string): Promise<Bulk>
lpos(
key: string,
element: RedisValue,
opts?: LPosOpts,
): Promise<Integer | BulkNil>

Returns the index of the first matching element inside a list. If no match is found, this method returns undefined.

lpos(
key: string,
element: RedisValue,
): Promise<Integer[]>

Returns the indexes of the first N matching elements inside a list. If no match is found. this method returns an empty array.

lpush(key: string, ...elements: RedisValue[]): Promise<Integer>
lpushx(key: string, ...elements: RedisValue[]): Promise<Integer>
lrange(
key: string,
start: number,
stop: number,
): Promise<BulkString[]>
lrem(
key: string,
count: number,
element: RedisValue,
): Promise<Integer>
lset(
key: string,
index: number,
element: RedisValue,
): Promise<SimpleString>
ltrim(
key: string,
start: number,
stop: number,
): Promise<SimpleString>
rpop(key: string): Promise<Bulk>
rpoplpush(source: string, destination: string): Promise<Bulk>
rpush(key: string, ...elements: RedisValue[]): Promise<Integer>
rpushx(key: string, ...elements: RedisValue[]): Promise<Integer>
pfadd(key: string, ...elements: string[]): Promise<Integer>
pfcount(...keys: string[]): Promise<Integer>
pfmerge(destkey: string, ...sourcekeys: string[]): Promise<SimpleString>
psubscribe<TMessage extends string | string[] = string>(...patterns: string[]): Promise<RedisSubscription<TMessage>>
pubsubChannels(pattern?: string): Promise<BulkString[]>
pubsubNumsub(...channels: string[]): Promise<(BulkString | Integer)[]>
pubsubNumpat(): Promise<Integer>
publish(channel: string, message: RedisValue): Promise<Integer>
subscribe<TMessage extends string | string[] = string>(...channels: string[]): Promise<RedisSubscription<TMessage>>
sadd(key: string, ...members: RedisValue[]): Promise<Integer>
scard(key: string): Promise<Integer>
sdiff(...keys: string[]): Promise<BulkString[]>
sdiffstore(destination: string, ...keys: string[]): Promise<Integer>
sinter(...keys: string[]): Promise<BulkString[]>
sinterstore(destination: string, ...keys: string[]): Promise<Integer>
sismember(key: string, member: RedisValue): Promise<Integer>
smembers(key: string): Promise<BulkString[]>
smove(
source: string,
destination: string,
member: RedisValue,
): Promise<Integer>
spop(key: string): Promise<Bulk>
spop(key: string, count: number): Promise<BulkString[]>
srandmember(key: string): Promise<Bulk>
srandmember(key: string, count: number): Promise<BulkString[]>
srem(key: string, ...members: RedisValue[]): Promise<Integer>
sscan(
key: string,
cursor: number,
opts?: SScanOpts,
): Promise<[BulkString, BulkString[]]>
sunion(...keys: string[]): Promise<BulkString[]>
sunionstore(destination: string, ...keys: string[]): Promise<Integer>
xack(
key: string,
group: string,
...xids: XIdInput[],
): Promise<Integer>

The XACK command removes one or multiple messages from the pending entries list (PEL) of a stream consumer group. A message is pending, and as such stored inside the PEL, when it was delivered to some consumer, normally as a side effect of calling XREADGROUP, or when a consumer took ownership of a message calling XCLAIM. The pending message was delivered to some consumer but the server is yet not sure it was processed at least once. So new calls to XREADGROUP to grab the messages history for a consumer (for instance using an XId of 0), will return such message. Similarly the pending message will be listed by the XPENDING command, that inspects the PEL.

Once a consumer successfully processes a message, it should call XACK so that such message does not get processed again, and as a side effect, the PEL entry about this message is also purged, releasing memory from the Redis server.

xadd(
key: string,
xid: XIdAdd,
field_values: XAddFieldValues,
): Promise<XId>

Write a message to a stream.

Returns bulk string reply, specifically: The command returns the XId of the added entry. The XId is the one auto-generated if * is passed as XId argument, otherwise the command just returns the same XId specified by the user during insertion.

xadd(
key: string,
xid: XIdAdd,
field_values: XAddFieldValues,
maxlen: XMaxlen,
): Promise<XId>

Write a message to a stream.

Returns bulk string reply, specifically: The command returns the XId of the added entry. The XId is the one auto-generated if * is passed as XId argument, otherwise the command just returns the same XId specified by the user during insertion.

xclaim(
key: string,
opts: XClaimOpts,
...xids: XIdInput[],
): Promise<XClaimReply>

In the context of a stream consumer group, this command changes the ownership of a pending message, so that the new owner is the consumer specified as the command argument.

It returns the claimed messages unless called with the JUSTIDs option, in which case it returns only their XIds.

This is a complex command! Read more at https://redis.io/commands/xclaim

xdel(key: string, ...xids: XIdInput[]): Promise<Integer>

Removes the specified entries from a stream, and returns the number of entries deleted, that may be different from the number of XIds passed to the command in case certain XIds do not exist.

xgroupCreate(
key: string,
groupName: string,
xid: XIdInput | "$",
mkstream?: boolean,
): Promise<SimpleString>

This command is used to create a new consumer group associated with a stream.

See https://redis.io/commands/xgroup

xgroupDelConsumer(
key: string,
groupName: string,
consumerName: string,
): Promise<Integer>

Delete a specific consumer from a group, leaving the group itself intact.

xgroupDestroy(key: string, groupName: string): Promise<Integer>

Destroy a consumer group completely. The consumer group will be destroyed even if there are active consumers and pending messages, so make sure to call this command only when really needed.

xgroupHelp(): Promise<BulkString>

A support command which displays text about the various subcommands in XGROUP.

xgroupSetID(
key: string,
groupName: string,
xid: XIdInput,
): Promise<SimpleString>

Finally it possible to set the next message to deliver using the SETID subcommand. Normally the next XId is set when the consumer is created, as the last argument of XGROUP CREATE. However using this form the next XId can be modified later without deleting and creating the consumer group again. For instance if you want the consumers in a consumer group to re-process all the messages in a stream, you may want to set its next ID to 0:

xinfoStream(key: string): Promise<XInfoStreamReply>
xinfoStreamFull(key: string, count?: number): Promise<XInfoStreamFullReply>

returns the entire state of the stream, including entries, groups, consumers and PELs. This form is available since Redis 6.0.

xinfoGroups(key: string): Promise<XInfoGroupsReply>

Get as output all the consumer groups associated with the stream.

xinfoConsumers(key: string, group: string): Promise<XInfoConsumersReply>

Get the list of every consumer in a specific consumer group.

xlen(key: string): Promise<Integer>

Returns the number of entries inside a stream. If the specified key does not exist the command returns zero, as if the stream was empty. However note that unlike other Redis types, zero-length streams are possible, so you should call TYPE or EXISTS in order to check if a key exists or not.

xpending(key: string, group: string): Promise<XPendingReply>

Complex command to obtain info on messages in the Pending Entries List.

Outputs a summary about the pending messages in a given consumer group.

xpendingCount(
key: string,
group: string,
startEndCount: StartEndCount,
consumer?: string,
): Promise<XPendingCount[]>

Output more detailed info about pending messages:

  • The ID of the message.
  • The name of the consumer that fetched the message and has still to acknowledge it. We call it the current owner of the message.
  • The number of milliseconds that elapsed since the last time this message was delivered to this consumer.
  • The number of times this message was delivered.

If you pass the consumer argument to the command, it will efficiently filter for messages owned by that consumer.

xrange(
key: string,
start: XIdNeg,
end: XIdPos,
count?: number,
): Promise<XMessage[]>

The command returns the stream entries matching a given range of XIds. The range is specified by a minimum and maximum ID. All the entries having an XId between the two specified or exactly one of the two XIds specified (closed interval) are returned.

The command also has a reciprocal command returning items in the reverse order, called XREVRANGE, which is otherwise identical.

The - and + special XIds mean respectively the minimum XId possible and the maximum XId possible inside a stream, so the following command will just return every entry in the stream.

xrevrange(
key: string,
start: XIdPos,
end: XIdNeg,
count?: number,
): Promise<XMessage[]>

This command is exactly like XRANGE, but with the notable difference of returning the entries in reverse order, and also taking the start-end range in reverse order: in XREVRANGE you need to state the end XId and later the start ID, and the command will produce all the element between (or exactly like) the two XIds, starting from the end side.

xread(key_xids: (XKeyId | XKeyIdLike)[], opts?: XReadOpts): Promise<XReadReply>

Read data from one or multiple streams, only returning entries with an XId greater than the last received XId reported by the caller.

xreadgroup(key_xids: (XKeyIdGroup | XKeyIdGroupLike)[], opts: XReadGroupOpts): Promise<XReadReply>

The XREADGROUP command is a special version of the XREAD command with support for consumer groups.

xtrim(key: string, maxlen: XMaxlen): Promise<Integer>

Trims the stream to the indicated number of elements.

bzpopmin(timeout: number, ...keys: string[]): Promise<[BulkString, BulkString, BulkString] | BulkNil>
bzpopmax(timeout: number, ...keys: string[]): Promise<[BulkString, BulkString, BulkString] | BulkNil>
zadd(
key: string,
score: number,
member: RedisValue,
opts?: ZAddOpts,
): Promise<Integer>
zadd(
key: string,
score_members: [number, RedisValue][],
opts?: ZAddOpts,
): Promise<Integer>
zadd(
key: string,
member_scores: Record<string | number, number>,
opts?: ZAddOpts,
): Promise<Integer>
zaddIncr(
key: string,
score: number,
member: RedisValue,
opts?: ZAddOpts,
): Promise<Bulk>
zcard(key: string): Promise<Integer>
zcount(
key: string,
min: number,
max: number,
): Promise<Integer>
zincrby(
key: string,
increment: number,
member: RedisValue,
): Promise<BulkString>
zinter(keys: string[], opts?: ZInterOpts): Promise<Raw[]>
zinter(key_weights: [string, number][], opts?: ZInterOpts): Promise<Raw[]>
zinter(key_weights: Record<string, number>, opts?: ZInterOpts): Promise<Raw[]>
zinterstore(
destination: string,
keys: string[],
): Promise<Integer>
zinterstore(
destination: string,
key_weights: [string, number][],
): Promise<Integer>
zinterstore(
destination: string,
key_weights: Record<string, number>,
): Promise<Integer>
zlexcount(
key: string,
min: string,
max: string,
): Promise<Integer>
zpopmax(key: string, count?: number): Promise<BulkString[]>
zpopmin(key: string, count?: number): Promise<BulkString[]>
zrange(
key: string,
start: number,
stop: number,
opts?: ZRangeOpts,
): Promise<BulkString[]>
zrangebylex(
key: string,
min: string,
max: string,
): Promise<BulkString[]>
zrangebyscore(
key: string,
min: number | string,
max: number | string,
): Promise<BulkString[]>
zrank(key: string, member: RedisValue): Promise<Integer | BulkNil>
zrem(key: string, ...members: RedisValue[]): Promise<Integer>
zremrangebylex(
key: string,
min: string,
max: string,
): Promise<Integer>
zremrangebyrank(
key: string,
start: number,
stop: number,
): Promise<Integer>
zremrangebyscore(
key: string,
min: number | string,
max: number | string,
): Promise<Integer>
zrevrange(
key: string,
start: number,
stop: number,
opts?: ZRangeOpts,
): Promise<BulkString[]>
zrevrangebylex(
key: string,
max: string,
min: string,
): Promise<BulkString[]>
zrevrangebyscore(
key: string,
max: number | string,
min: number | string,
): Promise<BulkString[]>
zrevrank(key: string, member: RedisValue): Promise<Integer | BulkNil>
zscan(
key: string,
cursor: number,
opts?: ZScanOpts,
): Promise<[BulkString, BulkString[]]>
zscore(key: string, member: RedisValue): Promise<Bulk>