├── .gitattributes ├── sources ├── command │ ├── utils │ │ └── index.ts │ ├── basic.ts │ ├── save.ts │ ├── reset.ts │ ├── flushdb.ts │ ├── unwatch.ts │ ├── acl.save.ts │ ├── flushall.ts │ ├── bgrewriteaof.ts │ ├── script.kill.ts │ ├── function.kill.ts │ ├── memory.purge.ts │ ├── slowlog.reset.ts │ ├── sync.ts │ ├── acl.whoami.ts │ ├── client.unpause.ts │ ├── config.rewrite.ts │ ├── dbsize.ts │ ├── acl.help.ts │ ├── acl.list.ts │ ├── acl.users.ts │ ├── config.resetstat.ts │ ├── lastsave.ts │ ├── client.id.ts │ ├── slowlog.len.ts │ ├── client.info.ts │ ├── command.count.ts │ ├── pubsub.numpat.ts │ ├── select.ts │ ├── ttl.ts │ ├── watch.ts │ ├── client.getredir.ts │ ├── decr.ts │ ├── function.dump.ts │ ├── hlen.ts │ ├── incr.ts │ ├── llen.ts │ ├── memory.doctor.ts │ ├── pttl.ts │ ├── scard.ts │ ├── xlen.ts │ ├── zcard.ts │ ├── client.help.ts │ ├── client.kill.ts │ ├── config.help.ts │ ├── latency.doctor.ts │ ├── memory.help.ts │ ├── module.help.ts │ ├── module.unload.ts │ ├── object.help.ts │ ├── pubsub.help.ts │ ├── randomkey.ts │ ├── script.help.ts │ ├── strlen.ts │ ├── xinfo.help.ts │ ├── bf.card.ts │ ├── command.help.ts │ ├── latency.help.ts │ ├── persist.ts │ ├── slowlog.help.ts │ ├── del.ts │ ├── expiretime.ts │ ├── memory.malloc-stats.ts │ ├── touch.ts │ ├── unlink.ts │ ├── client.getname.ts │ ├── client.trackinginfo.ts │ ├── dump.ts │ ├── echo.ts │ ├── get.ts │ ├── hkeys.ts │ ├── hvals.ts │ ├── lpop.ts │ ├── pexpiretime.ts │ ├── pfcount.ts │ ├── rpop.ts │ ├── spop.ts │ ├── exists.ts │ ├── function.delete.ts │ ├── smembers.ts │ ├── append.ts │ ├── getdel.ts │ ├── rename.ts │ ├── replicaof.ts │ ├── script.load.ts │ ├── client.setname.ts │ ├── swapdb.ts │ ├── move.ts │ ├── httl.ts │ ├── keys.ts │ ├── hpttl.ts │ ├── script.debug.ts │ ├── sdiff.ts │ ├── acl.deluser.ts │ ├── cf.count.ts │ ├── client.caching.ts │ ├── client.no-evict.ts │ ├── client.no-touch.ts │ ├── hexists.ts │ ├── hstrlen.ts │ ├── object.encoding.ts │ ├── sinter.ts │ ├── sunion.ts │ ├── xdel.ts │ ├── getbit.ts │ ├── hpersist.ts │ ├── hgetall.ts │ ├── renamenx.ts │ ├── sismember.ts │ ├── subscribe.ts │ ├── client.reply.ts │ ├── hexpiretime.ts │ ├── hpexpiretime.ts │ ├── psubscribe.ts │ ├── ssubscribe.ts │ ├── unsubscribe.ts │ ├── xtrim.ts │ ├── config.set.ts │ ├── mget.ts │ ├── punsubscribe.ts │ ├── sunsubscribe.ts │ ├── bgsave.ts │ ├── acl.genpass.ts │ ├── bf.add.ts │ ├── cf.add.ts │ ├── cf.del.ts │ ├── hget.ts │ ├── script.exists.ts │ ├── bf.exists.ts │ ├── cf.addnx.ts │ ├── cf.exists.ts │ ├── expire.ts │ ├── hdel.ts │ ├── pfadd.ts │ ├── sadd.ts │ ├── srem.ts │ ├── zrem.ts │ ├── decrby.ts │ ├── incrby.ts │ ├── lpushx.ts │ ├── pfmerge.ts │ ├── ping.ts │ ├── acl.setuser.ts │ ├── bf.madd.ts │ ├── client.setinfo.ts │ ├── lpush.ts │ ├── publish.ts │ ├── rpush.ts │ ├── latency.graph.ts │ ├── lindex.ts │ ├── ltrim.ts │ ├── spublish.ts │ ├── bf.mexists.ts │ ├── lset.ts │ ├── incrbyfloat.ts │ ├── setnx.ts │ ├── xgroup.destroy.ts │ ├── replconf.ts │ ├── sdiffstore.ts │ ├── wait.ts │ ├── xack.ts │ ├── zcount.ts │ ├── zlexcount.ts │ ├── acl.cat.ts │ ├── function.flush.ts │ ├── sinterstore.ts │ ├── sunionstore.ts │ ├── bf.loadchunk.ts │ ├── cf.loadchunk.ts │ ├── debug.ts │ ├── ts.deleterule.ts │ ├── zadd.ts │ ├── lrem.ts │ ├── zremrangebylex.ts │ ├── getrange.ts │ ├── hexpire.ts │ ├── zdiffstore.ts │ ├── config.get.ts │ ├── object.freq.ts │ ├── rpoplpush.ts │ ├── hincrby.ts │ ├── json.del.ts │ ├── json.toggle.ts │ ├── lrange.ts │ ├── zremrangebyscore.ts │ ├── zrevrangebylex.ts │ ├── hexpireat.ts │ ├── json.clear.ts │ ├── zincrby.ts │ ├── zrevrange.ts │ ├── hmget.ts │ ├── json.forget.ts │ ├── json.mget.ts │ ├── object.idletime.ts │ ├── object.refcount.ts │ ├── command.getkeys.ts │ ├── zrevrangebyscore.ts │ ├── hincrbyfloat.ts │ ├── rpushx.ts │ ├── json.numincrby.ts │ ├── json.nummultby.ts │ ├── msetnx.ts │ ├── pubsub.channels.ts │ ├── smove.ts │ ├── hpexpire.ts │ ├── setbit.ts │ ├── smismember.ts │ ├── pubsub.shardchannels.ts │ ├── evalsha.ts │ ├── sintercard.ts │ ├── acl.dryrun.ts │ ├── eval.ro.ts │ ├── eval.ts │ ├── module.load.ts │ ├── evalsha.ro.ts │ ├── json.mset.ts │ ├── latency.reset.ts │ ├── setex.ts │ ├── ts.del.ts │ ├── hset.ts │ ├── json.arrappend.ts │ ├── zrank.ts │ ├── zscore.ts │ ├── hpexpireat.ts │ ├── hsetnx.ts │ ├── xgroup.delconsumer.ts │ ├── brpoplpush.ts │ ├── function.load.ts │ ├── mset.ts │ ├── psetex.ts │ ├── zrevrank.ts │ ├── json.merge.ts │ ├── xgroup.createconsumer.ts │ ├── setrange.ts │ ├── ts.alter.ts │ ├── ts.create.ts │ ├── fcall.ts │ ├── fcall.ro.ts │ ├── json.arrlen.ts │ ├── json.objkeys.ts │ ├── json.objlen.ts │ ├── json.strlen.ts │ ├── script.flush.ts │ ├── xadd.ts │ ├── json.resp.ts │ ├── get.buffer.ts │ ├── auth.ts │ ├── module.list.ts │ ├── json.arrinsert.ts │ ├── expireat.ts │ ├── xrange.ts │ ├── client.pause.ts │ ├── ts.madd.ts │ ├── json.strappend.ts │ ├── linsert.ts │ ├── json.arrpop.ts │ ├── pexpire.ts │ ├── xgroup.setid.ts │ ├── json.arrtrim.ts │ ├── lolwut.ts │ ├── time.ts │ ├── ts.decrby.ts │ ├── ts.incrby.ts │ ├── bitop.ts │ ├── getset.ts │ ├── pexpireat.ts │ ├── cf.mexists.ts │ ├── pipeline.ts │ ├── bitfield.ro.ts │ ├── zinterstore.ts │ ├── client.list.ts │ ├── lmove.ts │ ├── zunionstore.ts │ ├── xgroup.help.ts │ ├── function.help.ts │ ├── geodist.ts │ ├── zrangebylex.ts │ ├── ts.add.ts │ ├── srandmember.ts │ ├── command.list.ts │ ├── ts.info.ts │ ├── xsetid.ts │ ├── module.loadex.ts │ ├── ts.queryindex.ts │ ├── function.restore.ts │ ├── xrevrange.ts │ ├── client.unblock.ts │ ├── zintercard.ts │ ├── blmove.ts │ ├── hmset.ts │ ├── shutdown.ts │ ├── xgroup.create.ts │ ├── bitcount.ts │ ├── copy.ts │ ├── bf.reserve.ts │ ├── zrangestore.ts │ ├── scan.ts │ ├── type.ts │ ├── pubsub.numsub.ts │ ├── sscan.ts │ ├── bf.scandump.ts │ ├── json.arrindex.ts │ ├── bitpos.ts │ ├── ts.createrule.ts │ ├── cf.reserve.ts │ ├── pubsub.shardnumsub.ts │ ├── geohash.ts │ ├── json.set.ts │ ├── cf.insert.ts │ ├── cf.insertnx.ts │ ├── blpop.ts │ ├── brpop.ts │ ├── failover.ts │ ├── json.get.ts │ ├── geosearchstore.ts │ └── geoadd.ts ├── common │ ├── index.ts │ └── utils │ │ ├── index.ts │ │ └── debug.ts ├── types │ └── index.ts └── index.ts ├── website ├── app │ ├── favicon.ico │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── apple-touch-icon.png │ ├── android-chrome-192x192.png │ └── android-chrome-512x512.png ├── postcss.config.mjs ├── public │ ├── vercel.svg │ ├── window.svg │ ├── file.svg │ └── globe.svg ├── next.config.ts ├── lib │ └── utils.ts ├── next-env.d.ts ├── i18n │ └── request.ts ├── components.json ├── tsconfig.json └── components │ └── language-switcher.tsx ├── scripts └── esm │ └── register.js ├── .npmignore ├── .vscode ├── extensions.json └── settings.json ├── .editorconfig ├── .gitignore ├── tsconfig.json └── .github └── workflows └── build.yaml /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /sources/command/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './command.ts'; 2 | export * from './reply.ts'; 3 | -------------------------------------------------------------------------------- /sources/common/index.ts: -------------------------------------------------------------------------------- 1 | export * from './constants.ts'; 2 | export * from './utils/index.ts'; 3 | -------------------------------------------------------------------------------- /website/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcms-io/solidis/HEAD/website/app/favicon.ico -------------------------------------------------------------------------------- /website/app/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcms-io/solidis/HEAD/website/app/favicon-16x16.png -------------------------------------------------------------------------------- /website/app/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcms-io/solidis/HEAD/website/app/favicon-32x32.png -------------------------------------------------------------------------------- /scripts/esm/register.js: -------------------------------------------------------------------------------- 1 | import { register } from 'node:module'; 2 | 3 | register('./loader.js', import.meta.url); 4 | -------------------------------------------------------------------------------- /website/app/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcms-io/solidis/HEAD/website/app/apple-touch-icon.png -------------------------------------------------------------------------------- /sources/types/index.ts: -------------------------------------------------------------------------------- 1 | export * from './command.ts'; 2 | export * from './resp.ts'; 3 | export * from './solidis.ts'; 4 | -------------------------------------------------------------------------------- /website/app/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcms-io/solidis/HEAD/website/app/android-chrome-192x192.png -------------------------------------------------------------------------------- /website/app/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vcms-io/solidis/HEAD/website/app/android-chrome-512x512.png -------------------------------------------------------------------------------- /website/postcss.config.mjs: -------------------------------------------------------------------------------- 1 | const config = { 2 | plugins: ["@tailwindcss/postcss"], 3 | }; 4 | 5 | export default config; 6 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | 3 | !LICENSE 4 | !README.md 5 | !package.json 6 | 7 | !distributions/** 8 | 9 | distributions/tsconfig.tsbuildinfo 10 | -------------------------------------------------------------------------------- /website/public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sources/common/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './debug.ts'; 2 | export * from './error.ts'; 3 | export * from './reply.ts'; 4 | export * from './request.ts'; 5 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "biomejs.biome", 4 | "ms-vscode.vscode-typescript-next", 5 | "github.vscode-github-actions" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /sources/command/basic.ts: -------------------------------------------------------------------------------- 1 | export { auth } from './auth.ts'; 2 | export { hello } from './hello.ts'; 3 | export { info } from './info.ts'; 4 | export { select } from './select.ts'; 5 | -------------------------------------------------------------------------------- /website/next.config.ts: -------------------------------------------------------------------------------- 1 | import type { NextConfig } from "next"; 2 | 3 | const nextConfig: NextConfig = { 4 | /* config options here */ 5 | }; 6 | 7 | export default nextConfig; 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /website/lib/utils.ts: -------------------------------------------------------------------------------- 1 | import { clsx, type ClassValue } from "clsx" 2 | import { twMerge } from "tailwind-merge" 3 | 4 | export function cn(...inputs: ClassValue[]) { 5 | return twMerge(clsx(inputs)) 6 | } 7 | -------------------------------------------------------------------------------- /website/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. 6 | -------------------------------------------------------------------------------- /sources/command/save.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['SAVE']; 5 | } 6 | 7 | export async function save(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/reset.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['RESET']; 5 | } 6 | 7 | export async function reset(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/flushdb.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['FLUSHDB']; 5 | } 6 | 7 | export async function flushdb(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/unwatch.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['UNWATCH']; 5 | } 6 | 7 | export async function unwatch(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/acl.save.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['ACL', 'SAVE']; 5 | } 6 | 7 | export async function aclSave(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/flushall.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['FLUSHALL']; 5 | } 6 | 7 | export async function flushall(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/bgrewriteaof.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['BGREWRITEAOF']; 5 | } 6 | 7 | export async function bgrewriteaof(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/script.kill.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['SCRIPT', 'KILL']; 5 | } 6 | 7 | export async function scriptKill(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/function.kill.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['FUNCTION', 'KILL']; 5 | } 6 | 7 | export async function functionKill(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/memory.purge.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['MEMORY', 'PURGE']; 5 | } 6 | 7 | export async function memoryPurge(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/slowlog.reset.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['SLOWLOG', 'RESET']; 5 | } 6 | 7 | export async function slowlogReset(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/sync.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['SYNC']; 5 | } 6 | 7 | export async function sync(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToString); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/acl.whoami.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['ACL', 'WHOAMI']; 5 | } 6 | 7 | export async function aclWhoami(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyToString); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/client.unpause.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['CLIENT', 'UNPAUSE']; 5 | } 6 | 7 | export async function clientUnpause(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/config.rewrite.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['CONFIG', 'REWRITE']; 5 | } 6 | 7 | export async function configRewrite(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/dbsize.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['DBSIZE']; 5 | } 6 | 7 | export async function dbsize(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/acl.help.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['ACL', 'HELP']; 5 | } 6 | 7 | export async function aclHelp(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/acl.list.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['ACL', 'LIST']; 5 | } 6 | 7 | export async function aclList(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/acl.users.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['ACL', 'USERS']; 5 | } 6 | 7 | export async function aclUsers(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/config.resetstat.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['CONFIG', 'RESETSTAT']; 5 | } 6 | 7 | export async function configResetstat(this: T) { 8 | return await executeCommand(this, createCommand(), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/lastsave.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['LASTSAVE']; 5 | } 6 | 7 | export async function lastsave(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/index.ts: -------------------------------------------------------------------------------- 1 | export * from './client.ts'; 2 | export * from './common/index.ts'; 3 | export * from './modules/connection.ts'; 4 | export * from './modules/debug.ts'; 5 | export * from './modules/parser.ts'; 6 | export * from './modules/pubsub.ts'; 7 | export * from './modules/requester.ts'; 8 | export * from './types/index.ts'; 9 | -------------------------------------------------------------------------------- /sources/command/client.id.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['CLIENT', 'ID']; 5 | } 6 | 7 | export async function clientId(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/slowlog.len.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['SLOWLOG', 'LEN']; 5 | } 6 | 7 | export async function slowlogLen(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/client.info.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['CLIENT', 'INFO']; 5 | } 6 | 7 | export async function clientInfo(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToString); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/command.count.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['COMMAND', 'COUNT']; 5 | } 6 | 7 | export async function commandCount(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/pubsub.numpat.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['PUBSUB', 'NUMPAT']; 5 | } 6 | 7 | export async function pubsubNumpat(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/select.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(index: number) { 4 | return ['SELECT', `${index}`]; 5 | } 6 | 7 | export async function select(this: T, index: number) { 8 | return await executeCommand(this, createCommand(index), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/ttl.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['TTL', key]; 5 | } 6 | 7 | export async function ttl(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/watch.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(...keys: string[]) { 4 | return ['WATCH', ...keys]; 5 | } 6 | 7 | export async function watch(this: T, ...keys: string[]) { 8 | return await executeCommand(this, createCommand(...keys), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Distributions 2 | distributions 3 | 4 | # Windows 5 | Desktop.ini 6 | Thumbs.db 7 | $RECYCLE.BIN/ 8 | *.lnk 9 | 10 | # Mac OS X 11 | .DS_Store 12 | .AppleDouble 13 | .LSOverride 14 | ._* 15 | 16 | # IDE 17 | .idea/ 18 | *.swp 19 | *.swo 20 | 21 | # Node.js 22 | node_modules 23 | 24 | # Next.js 25 | .next/ 26 | *.tsbuildinfo 27 | -------------------------------------------------------------------------------- /sources/command/client.getredir.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['CLIENT', 'GETREDIR']; 5 | } 6 | 7 | export async function clientGetredir(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/decr.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['DECR', key]; 5 | } 6 | 7 | export async function decr(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/function.dump.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['FUNCTION', 'DUMP']; 5 | } 6 | 7 | export async function functionDump(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToString); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/hlen.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['HLEN', key]; 5 | } 6 | 7 | export async function hlen(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/incr.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['INCR', key]; 5 | } 6 | 7 | export async function incr(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/llen.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['LLEN', key]; 5 | } 6 | 7 | export async function llen(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/memory.doctor.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['MEMORY', 'DOCTOR']; 5 | } 6 | 7 | export async function memoryDoctor(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToString); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/pttl.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['PTTL', key]; 5 | } 6 | 7 | export async function pttl(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/scard.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['SCARD', key]; 5 | } 6 | 7 | export async function scard(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/xlen.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['XLEN', key]; 5 | } 6 | 7 | export async function xlen(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/zcard.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['ZCARD', key]; 5 | } 6 | 7 | export async function zcard(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/client.help.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['CLIENT', 'HELP']; 5 | } 6 | 7 | export async function clientHelp(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/client.kill.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(id: number) { 4 | return ['CLIENT', 'KILL', 'ID', `${id}`]; 5 | } 6 | 7 | export async function clientKill(this: T, id: number) { 8 | return await executeCommand(this, createCommand(id), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/config.help.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['CONFIG', 'HELP']; 5 | } 6 | 7 | export async function configHelp(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/latency.doctor.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['LATENCY', 'DOCTOR']; 5 | } 6 | 7 | export async function latencyDoctor(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToString); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/memory.help.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['MEMORY', 'HELP']; 5 | } 6 | 7 | export async function memoryHelp(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/module.help.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['MODULE', 'HELP']; 5 | } 6 | 7 | export async function moduleHelp(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/module.unload.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(name: string) { 4 | return ['MODULE', 'UNLOAD', name]; 5 | } 6 | 7 | export async function moduleUnload(this: T, name: string) { 8 | return await executeCommand(this, createCommand(name), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/object.help.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['OBJECT', 'HELP']; 5 | } 6 | 7 | export async function objectHelp(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/pubsub.help.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['PUBSUB', 'HELP']; 5 | } 6 | 7 | export async function pubsubHelp(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/randomkey.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['RANDOMKEY']; 5 | } 6 | 7 | export async function randomkey(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringOrNull); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/script.help.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['SCRIPT', 'HELP']; 5 | } 6 | 7 | export async function scriptHelp(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/strlen.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['STRLEN', key]; 5 | } 6 | 7 | export async function strlen(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/xinfo.help.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['XINFO', 'HELP']; 5 | } 6 | 7 | export async function xinfoHelp(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/bf.card.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['BF.CARD', key]; 5 | } 6 | 7 | export async function bfCard(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyToNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/command.help.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['COMMAND', 'HELP']; 5 | } 6 | 7 | export async function commandHelp(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/latency.help.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['LATENCY', 'HELP']; 5 | } 6 | 7 | export async function latencyHelp(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/persist.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['PERSIST', key]; 5 | } 6 | 7 | export async function persist(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/slowlog.help.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['SLOWLOG', 'HELP']; 5 | } 6 | 7 | export async function slowlogHelp(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/del.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(...keys: string[]) { 4 | return ['DEL', ...keys]; 5 | } 6 | 7 | export async function del(this: T, ...keys: string[]): Promise { 8 | return await executeCommand(this, createCommand(...keys), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/expiretime.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['EXPIRETIME', key]; 5 | } 6 | 7 | export async function expiretime(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/memory.malloc-stats.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['MEMORY', 'MALLOC-STATS']; 5 | } 6 | 7 | export async function memoryMallocStats(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToString); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/touch.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(keys: string[]) { 4 | return ['TOUCH', ...keys]; 5 | } 6 | 7 | export async function touch(this: T, keys: string[]): Promise { 8 | return await executeCommand(this, createCommand(keys), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/unlink.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(keys: string[]) { 4 | return ['UNLINK', ...keys]; 5 | } 6 | 7 | export async function unlink(this: T, keys: string[]): Promise { 8 | return await executeCommand(this, createCommand(keys), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/client.getname.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['CLIENT', 'GETNAME']; 5 | } 6 | 7 | export async function clientGetname(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToStringOrNull); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/client.trackinginfo.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand() { 4 | return ['CLIENT', 'TRACKINGINFO']; 5 | } 6 | 7 | export async function clientTrackinginfo(this: T): Promise { 8 | return await executeCommand(this, createCommand(), tryReplyToString); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/dump.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['DUMP', key]; 5 | } 6 | 7 | export async function dump(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyToStringOrNull); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/echo.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand(message: string) { 4 | return ['ECHO', message]; 5 | } 6 | 7 | export async function echo(this: T, message: string): Promise { 8 | return await executeCommand(this, createCommand(message), tryReplyToString); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/get.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['GET', key]; 5 | } 6 | 7 | export async function get(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyToStringOrNull); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/hkeys.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['HKEYS', key]; 5 | } 6 | 7 | export async function hkeys(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/hvals.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['HVALS', key]; 5 | } 6 | 7 | export async function hvals(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/lpop.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['LPOP', key]; 5 | } 6 | 7 | export async function lpop(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyToStringOrNull); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/pexpiretime.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['PEXPIRETIME', key]; 5 | } 6 | 7 | export async function pexpiretime(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/pfcount.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(keys: string[]) { 4 | return ['PFCOUNT', ...keys]; 5 | } 6 | 7 | export async function pfcount(this: T, keys: string[]): Promise { 8 | return await executeCommand(this, createCommand(keys), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/rpop.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['RPOP', key]; 5 | } 6 | 7 | export async function rpop(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyToStringOrNull); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/spop.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['SPOP', key]; 5 | } 6 | 7 | export async function spop(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyToStringOrNull); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/exists.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(...keys: string[]) { 4 | return ['EXISTS', ...keys]; 5 | } 6 | 7 | export async function exists(this: T, ...keys: string[]): Promise { 8 | return await executeCommand(this, createCommand(...keys), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/function.delete.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(library: string) { 4 | return ['FUNCTION', 'DELETE', library]; 5 | } 6 | 7 | export async function functionDelete(this: T, library: string) { 8 | return await executeCommand(this, createCommand(library), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/smembers.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['SMEMBERS', key]; 5 | } 6 | 7 | export async function smembers(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyToStringArray); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/append.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, value: string) { 4 | return ['APPEND', key, value]; 5 | } 6 | 7 | export async function append(this: T, key: string, value: string) { 8 | return await executeCommand(this, createCommand(key, value), tryReplyNumber); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/getdel.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['GETDEL', key]; 5 | } 6 | 7 | export async function getdel(this: T, key: string): Promise { 8 | return await executeCommand(this, createCommand(key), tryReplyToStringOrNull); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/rename.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, newkey: string) { 4 | return ['RENAME', key, newkey]; 5 | } 6 | 7 | export async function rename(this: T, key: string, newkey: string) { 8 | return await executeCommand(this, createCommand(key, newkey), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/replicaof.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(host: string, port: number) { 4 | return ['REPLICAOF', host, `${port}`]; 5 | } 6 | 7 | export async function replicaof(this: T, host: string, port: number) { 8 | return await executeCommand(this, createCommand(host, port), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/script.load.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand(script: string) { 4 | return ['SCRIPT', 'LOAD', script]; 5 | } 6 | 7 | export async function scriptLoad(this: T, script: string): Promise { 8 | return await executeCommand(this, createCommand(script), tryReplyToString); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/client.setname.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(connectionName: string) { 4 | return ['CLIENT', 'SETNAME', connectionName]; 5 | } 6 | 7 | export async function clientSetname(this: T, connectionName: string) { 8 | return await executeCommand(this, createCommand(connectionName), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /sources/command/swapdb.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(index1: number, index2: number) { 4 | return ['SWAPDB', `${index1}`, `${index2}`]; 5 | } 6 | 7 | export async function swapdb(this: T, index1: number, index2: number) { 8 | return await executeCommand(this, createCommand(index1, index2), tryReplyOK); 9 | } 10 | -------------------------------------------------------------------------------- /website/public/window.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /website/public/file.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sources/command/move.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, db: number) { 4 | return ['MOVE', key, `${db}`]; 5 | } 6 | 7 | export async function move( 8 | this: T, 9 | key: string, 10 | db: number, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, db), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/httl.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, field: string) { 4 | return ['HTTL', key, field]; 5 | } 6 | 7 | export async function httl( 8 | this: T, 9 | key: string, 10 | field: string, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, field), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/keys.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(pattern: string) { 4 | return ['KEYS', pattern]; 5 | } 6 | 7 | export async function keys(this: T, pattern: string): Promise { 8 | return await executeCommand( 9 | this, 10 | createCommand(pattern), 11 | tryReplyToStringArray, 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/hpttl.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, field: string) { 4 | return ['HPTTL', key, field]; 5 | } 6 | 7 | export async function hpttl( 8 | this: T, 9 | key: string, 10 | field: string, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, field), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/script.debug.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { RespYesOrNo } from '../index.ts'; 4 | 5 | export function createCommand(mode: RespYesOrNo) { 6 | return ['SCRIPT', 'DEBUG', mode]; 7 | } 8 | 9 | export async function scriptDebug(this: T, mode: RespYesOrNo) { 10 | return await executeCommand(this, createCommand(mode), tryReplyOK); 11 | } 12 | -------------------------------------------------------------------------------- /sources/command/sdiff.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(...keys: string[]) { 4 | return ['SDIFF', ...keys]; 5 | } 6 | 7 | export async function sdiff(this: T, ...keys: string[]): Promise { 8 | return await executeCommand( 9 | this, 10 | createCommand(...keys), 11 | tryReplyToStringArray, 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/acl.deluser.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(...usernames: string[]) { 4 | return ['ACL', 'DELUSER', ...usernames]; 5 | } 6 | 7 | export async function aclDeluser(this: T, ...usernames: string[]) { 8 | return await executeCommand( 9 | this, 10 | createCommand(...usernames), 11 | tryReplyNumber, 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/cf.count.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, item: string) { 4 | return ['CF.COUNT', key, item]; 5 | } 6 | 7 | export async function cfCount( 8 | this: T, 9 | key: string, 10 | item: string, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, item), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/client.caching.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { RespYesOrNo } from '../index.ts'; 4 | 5 | export function createCommand(mode: RespYesOrNo) { 6 | return ['CLIENT', 'CACHING', mode]; 7 | } 8 | 9 | export async function clientCaching(this: T, mode: RespYesOrNo) { 10 | return await executeCommand(this, createCommand(mode), tryReplyOK); 11 | } 12 | -------------------------------------------------------------------------------- /sources/command/client.no-evict.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { RespOnOrOff } from '../index.ts'; 4 | 5 | export function createCommand(mode: RespOnOrOff) { 6 | return ['CLIENT', 'NO-EVICT', mode]; 7 | } 8 | 9 | export async function clientNoEvict(this: T, mode: RespOnOrOff) { 10 | return await executeCommand(this, createCommand(mode), tryReplyOK); 11 | } 12 | -------------------------------------------------------------------------------- /sources/command/client.no-touch.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { RespOnOrOff } from '../index.ts'; 4 | 5 | export function createCommand(mode: RespOnOrOff) { 6 | return ['CLIENT', 'NO-TOUCH', mode]; 7 | } 8 | 9 | export async function clientNoTouch(this: T, mode: RespOnOrOff) { 10 | return await executeCommand(this, createCommand(mode), tryReplyOK); 11 | } 12 | -------------------------------------------------------------------------------- /sources/command/hexists.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, field: string) { 4 | return ['HEXISTS', key, field]; 5 | } 6 | 7 | export async function hexists( 8 | this: T, 9 | key: string, 10 | field: string, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, field), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/hstrlen.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, field: string) { 4 | return ['HSTRLEN', key, field]; 5 | } 6 | 7 | export async function hstrlen( 8 | this: T, 9 | key: string, 10 | field: string, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, field), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/object.encoding.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['OBJECT', 'ENCODING', key]; 5 | } 6 | 7 | export async function objectEncoding( 8 | this: T, 9 | key: string, 10 | ): Promise { 11 | return await executeCommand(this, createCommand(key), tryReplyToStringOrNull); 12 | } 13 | -------------------------------------------------------------------------------- /sources/command/sinter.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(...keys: string[]) { 4 | return ['SINTER', ...keys]; 5 | } 6 | 7 | export async function sinter(this: T, ...keys: string[]): Promise { 8 | return await executeCommand( 9 | this, 10 | createCommand(...keys), 11 | tryReplyToStringArray, 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/sunion.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(...keys: string[]) { 4 | return ['SUNION', ...keys]; 5 | } 6 | 7 | export async function sunion(this: T, ...keys: string[]): Promise { 8 | return await executeCommand( 9 | this, 10 | createCommand(...keys), 11 | tryReplyToStringArray, 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/xdel.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, ...ids: string[]) { 4 | return ['XDEL', key, ...ids]; 5 | } 6 | 7 | export async function xdel( 8 | this: T, 9 | key: string, 10 | ...ids: string[] 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, ...ids), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/getbit.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, offset: number) { 4 | return ['GETBIT', key, `${offset}`]; 5 | } 6 | 7 | export async function getbit( 8 | this: T, 9 | key: string, 10 | offset: number, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, offset), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/hpersist.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, field: string) { 4 | return ['HPERSIST', key, field]; 5 | } 6 | 7 | export async function hpersist( 8 | this: T, 9 | key: string, 10 | field: string, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, field), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/hgetall.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringRecord } from './utils/index.ts'; 2 | 3 | import type { RespHashField } from '../index.ts'; 4 | 5 | export function createCommand(key: string) { 6 | return ['HGETALL', key]; 7 | } 8 | 9 | export async function hgetall(this: T, key: string): Promise { 10 | return await executeCommand(this, createCommand(key), tryReplyToStringRecord); 11 | } 12 | -------------------------------------------------------------------------------- /sources/command/renamenx.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, newkey: string) { 4 | return ['RENAMENX', key, newkey]; 5 | } 6 | 7 | export async function renamenx( 8 | this: T, 9 | key: string, 10 | newkey: string, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, newkey), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/sismember.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, member: string) { 4 | return ['SISMEMBER', key, member]; 5 | } 6 | 7 | export async function sismember( 8 | this: T, 9 | key: string, 10 | member: string, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, member), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/subscribe.ts: -------------------------------------------------------------------------------- 1 | import { guard } from './utils/index.ts'; 2 | 3 | export function createCommand(...channels: string[]) { 4 | return ['SUBSCRIBE', ...channels]; 5 | } 6 | 7 | export async function subscribe( 8 | this: T, 9 | ...channels: string[] 10 | ): Promise { 11 | if (!guard(this)) { 12 | return undefined as never; 13 | } 14 | 15 | await this.send([createCommand(...channels)]); 16 | } 17 | -------------------------------------------------------------------------------- /sources/command/client.reply.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { RespClientReplyMode } from '../index.ts'; 4 | 5 | export function createCommand(mode: RespClientReplyMode) { 6 | return ['CLIENT', 'REPLY', mode]; 7 | } 8 | 9 | export async function clientReply(this: T, mode: RespClientReplyMode) { 10 | return await executeCommand(this, createCommand(mode), tryReplyOK); 11 | } 12 | -------------------------------------------------------------------------------- /sources/command/hexpiretime.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, field: string) { 4 | return ['HEXPIRETIME', key, field]; 5 | } 6 | 7 | export async function hexpiretime( 8 | this: T, 9 | key: string, 10 | field: string, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, field), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/hpexpiretime.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, field: string) { 4 | return ['HPEXPIRETIME', key, field]; 5 | } 6 | 7 | export async function hpexpiretime( 8 | this: T, 9 | key: string, 10 | field: string, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, field), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/psubscribe.ts: -------------------------------------------------------------------------------- 1 | import { guard } from './utils/index.ts'; 2 | 3 | export function createCommand(...patterns: string[]) { 4 | return ['PSUBSCRIBE', ...patterns]; 5 | } 6 | 7 | export async function psubscribe( 8 | this: T, 9 | ...patterns: string[] 10 | ): Promise { 11 | if (!guard(this)) { 12 | return undefined as never; 13 | } 14 | 15 | await this.send([createCommand(...patterns)]); 16 | } 17 | -------------------------------------------------------------------------------- /sources/command/ssubscribe.ts: -------------------------------------------------------------------------------- 1 | import { guard } from './utils/index.ts'; 2 | 3 | export function createCommand(...channels: string[]) { 4 | return ['SSUBSCRIBE', ...channels]; 5 | } 6 | 7 | export async function ssubscribe( 8 | this: T, 9 | ...channels: string[] 10 | ): Promise { 11 | if (!guard(this)) { 12 | return undefined as never; 13 | } 14 | 15 | await this.send([createCommand(...channels)]); 16 | } 17 | -------------------------------------------------------------------------------- /sources/command/unsubscribe.ts: -------------------------------------------------------------------------------- 1 | import { guard } from './utils/index.ts'; 2 | 3 | export function createCommand(...channels: string[]) { 4 | return ['UNSUBSCRIBE', ...channels]; 5 | } 6 | 7 | export async function unsubscribe( 8 | this: T, 9 | ...channels: string[] 10 | ): Promise { 11 | if (!guard(this)) { 12 | return undefined as never; 13 | } 14 | 15 | await this.send([createCommand(...channels)]); 16 | } 17 | -------------------------------------------------------------------------------- /sources/command/xtrim.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, maxlen: number) { 4 | return ['XTRIM', key, 'MAXLEN', `${maxlen}`]; 5 | } 6 | 7 | export async function xtrim( 8 | this: T, 9 | key: string, 10 | maxlen: number, 11 | ): Promise { 12 | return await executeCommand(this, createCommand(key, maxlen), tryReplyNumber); 13 | } 14 | -------------------------------------------------------------------------------- /sources/common/utils/debug.ts: -------------------------------------------------------------------------------- 1 | import type { SolidisDebugLogType, SolidisDebugMemory } from '../../index.ts'; 2 | 3 | export function generateDebugHandle(debugMemory?: SolidisDebugMemory) { 4 | if (!debugMemory) { 5 | return; 6 | } 7 | 8 | return (type: SolidisDebugLogType, message: string, data?: unknown) => { 9 | debugMemory.write({ 10 | type, 11 | message, 12 | data, 13 | }); 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /sources/command/config.set.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(parameter: string, value: string) { 4 | return ['CONFIG', 'SET', parameter, value]; 5 | } 6 | 7 | export async function configSet(this: T, parameter: string, value: string) { 8 | return await executeCommand( 9 | this, 10 | createCommand(parameter, value), 11 | tryReplyOK, 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /sources/command/mget.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(...keys: string[]) { 4 | return ['MGET', ...keys]; 5 | } 6 | 7 | export async function mget( 8 | this: T, 9 | ...keys: string[] 10 | ): Promise<(string | null)[]> { 11 | return await executeCommand( 12 | this, 13 | createCommand(...keys), 14 | tryReplyToStringArray, 15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /sources/command/punsubscribe.ts: -------------------------------------------------------------------------------- 1 | import { guard } from './utils/index.ts'; 2 | 3 | export function createCommand(...patterns: string[]) { 4 | return ['PUNSUBSCRIBE', ...patterns]; 5 | } 6 | 7 | export async function punsubscribe( 8 | this: T, 9 | ...patterns: string[] 10 | ): Promise { 11 | if (!guard(this)) { 12 | return undefined as never; 13 | } 14 | 15 | await this.send([createCommand(...patterns)]); 16 | } 17 | -------------------------------------------------------------------------------- /sources/command/sunsubscribe.ts: -------------------------------------------------------------------------------- 1 | import { guard } from './utils/index.ts'; 2 | 3 | export function createCommand(...channels: string[]) { 4 | return ['SUNSUBSCRIBE', ...channels]; 5 | } 6 | 7 | export async function sunsubscribe( 8 | this: T, 9 | ...channels: string[] 10 | ): Promise { 11 | if (!guard(this)) { 12 | return undefined as never; 13 | } 14 | 15 | await this.send([createCommand(...channels)]); 16 | } 17 | -------------------------------------------------------------------------------- /sources/command/bgsave.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(schedule?: boolean) { 4 | const command = ['BGSAVE']; 5 | 6 | if (schedule) { 7 | command.push('SCHEDULE'); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function bgsave(this: T, schedule?: boolean) { 14 | return await executeCommand(this, createCommand(schedule), tryReplyOK); 15 | } 16 | -------------------------------------------------------------------------------- /sources/command/acl.genpass.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand(bits?: number) { 4 | const command = ['ACL', 'GENPASS']; 5 | 6 | if (bits) { 7 | command.push(`${bits}`); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function aclGenpass(this: T, bits?: number) { 14 | return await executeCommand(this, createCommand(bits), tryReplyToString); 15 | } 16 | -------------------------------------------------------------------------------- /sources/command/bf.add.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToBoolean } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, item: string) { 4 | return ['BF.ADD', key, item]; 5 | } 6 | 7 | export async function bfAdd( 8 | this: T, 9 | key: string, 10 | item: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, item), 15 | tryReplyToBoolean, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/cf.add.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToBoolean } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, item: string) { 4 | return ['CF.ADD', key, item]; 5 | } 6 | 7 | export async function cfAdd( 8 | this: T, 9 | key: string, 10 | item: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, item), 15 | tryReplyToBoolean, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/cf.del.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToBoolean } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, item: string) { 4 | return ['CF.DEL', key, item]; 5 | } 6 | 7 | export async function cfDel( 8 | this: T, 9 | key: string, 10 | item: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, item), 15 | tryReplyToBoolean, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /website/i18n/request.ts: -------------------------------------------------------------------------------- 1 | import { getRequestConfig } from 'next-intl/server'; 2 | import { cookies } from 'next/headers'; 3 | 4 | export default getRequestConfig(async () => { 5 | // Get locale from cookie or default to 'en' 6 | const cookieStore = await cookies(); 7 | const locale = cookieStore.get('locale')?.value || 'en'; 8 | 9 | return { 10 | locale, 11 | messages: (await import(`./messages/${locale}.json`)).default 12 | }; 13 | }); 14 | -------------------------------------------------------------------------------- /sources/command/hget.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, field: string) { 4 | return ['HGET', key, field]; 5 | } 6 | 7 | export async function hget( 8 | this: T, 9 | key: string, 10 | field: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, field), 15 | tryReplyToString, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/script.exists.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | export function createCommand(sha1s: string[]) { 4 | return ['SCRIPT', 'EXISTS', ...sha1s]; 5 | } 6 | 7 | export async function scriptExists( 8 | this: T, 9 | sha1s: string[], 10 | ): Promise { 11 | return await executeCommand( 12 | this, 13 | createCommand(sha1s), 14 | tryReplyToNumberArray, 15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /sources/command/bf.exists.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToBoolean } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, item: string) { 4 | return ['BF.EXISTS', key, item]; 5 | } 6 | 7 | export async function bfExists( 8 | this: T, 9 | key: string, 10 | item: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, item), 15 | tryReplyToBoolean, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/cf.addnx.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToBoolean } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, item: string) { 4 | return ['CF.ADDNX', key, item]; 5 | } 6 | 7 | export async function cfAddnx( 8 | this: T, 9 | key: string, 10 | item: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, item), 15 | tryReplyToBoolean, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/cf.exists.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToBoolean } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, item: string) { 4 | return ['CF.EXISTS', key, item]; 5 | } 6 | 7 | export async function cfExists( 8 | this: T, 9 | key: string, 10 | item: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, item), 15 | tryReplyToBoolean, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/expire.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, seconds: number) { 4 | return ['EXPIRE', key, `${seconds}`]; 5 | } 6 | 7 | export async function expire( 8 | this: T, 9 | key: string, 10 | seconds: number, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, seconds), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/hdel.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, ...fields: string[]) { 4 | return ['HDEL', key, ...fields]; 5 | } 6 | 7 | export async function hdel( 8 | this: T, 9 | key: string, 10 | ...fields: string[] 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, ...fields), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/pfadd.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, elements: string[]) { 4 | return ['PFADD', key, ...elements]; 5 | } 6 | 7 | export async function pfadd( 8 | this: T, 9 | key: string, 10 | elements: string[], 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, elements), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/sadd.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, ...members: string[]) { 4 | return ['SADD', key, ...members]; 5 | } 6 | 7 | export async function sadd( 8 | this: T, 9 | key: string, 10 | ...members: string[] 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, ...members), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/srem.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, ...members: string[]) { 4 | return ['SREM', key, ...members]; 5 | } 6 | 7 | export async function srem( 8 | this: T, 9 | key: string, 10 | ...members: string[] 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, ...members), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/zrem.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, ...members: string[]) { 4 | return ['ZREM', key, ...members]; 5 | } 6 | 7 | export async function zrem( 8 | this: T, 9 | key: string, 10 | ...members: string[] 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, ...members), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/decrby.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, decrement: number) { 4 | return ['DECRBY', key, `${decrement}`]; 5 | } 6 | 7 | export async function decrby( 8 | this: T, 9 | key: string, 10 | decrement: number, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, decrement), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/incrby.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, increment: number) { 4 | return ['INCRBY', key, `${increment}`]; 5 | } 6 | 7 | export async function incrby( 8 | this: T, 9 | key: string, 10 | increment: number, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, increment), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/lpushx.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, elements: string[]) { 4 | return ['LPUSHX', key, ...elements]; 5 | } 6 | 7 | export async function lpushx( 8 | this: T, 9 | key: string, 10 | elements: string[], 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, elements), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/pfmerge.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(destkey: string, sourcekeys: string[]) { 4 | return ['PFMERGE', destkey, ...sourcekeys]; 5 | } 6 | 7 | export async function pfmerge( 8 | this: T, 9 | destkey: string, 10 | sourcekeys: string[], 11 | ) { 12 | return await executeCommand( 13 | this, 14 | createCommand(destkey, sourcekeys), 15 | tryReplyOK, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/ping.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand(message?: string) { 4 | const command = ['PING']; 5 | 6 | if (message !== undefined) { 7 | command.push(message); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function ping(this: T, message?: string): Promise { 14 | return await executeCommand(this, createCommand(message), tryReplyToString); 15 | } 16 | -------------------------------------------------------------------------------- /sources/command/acl.setuser.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(username: string, ...rules: string[]) { 4 | return ['ACL', 'SETUSER', username, ...rules]; 5 | } 6 | 7 | export async function aclSetuser( 8 | this: T, 9 | username: string, 10 | ...rules: string[] 11 | ) { 12 | return await executeCommand( 13 | this, 14 | createCommand(username, ...rules), 15 | tryReplyOK, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/bf.madd.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, items: string[]) { 4 | return ['BF.MADD', key, ...items]; 5 | } 6 | 7 | export async function bfMadd( 8 | this: T, 9 | key: string, 10 | items: string[], 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, items), 15 | tryReplyToNumberArray, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/client.setinfo.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(attribute: string, value: string) { 4 | return ['CLIENT', 'SETINFO', attribute, value]; 5 | } 6 | 7 | export async function clientSetinfo( 8 | this: T, 9 | attribute: string, 10 | value: string, 11 | ) { 12 | return await executeCommand( 13 | this, 14 | createCommand(attribute, value), 15 | tryReplyOK, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/lpush.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, ...elements: string[]) { 4 | return ['LPUSH', key, ...elements]; 5 | } 6 | 7 | export async function lpush( 8 | this: T, 9 | key: string, 10 | ...elements: string[] 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, ...elements), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/publish.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(channel: string, message: string) { 4 | return ['PUBLISH', channel, message]; 5 | } 6 | 7 | export async function publish( 8 | this: T, 9 | channel: string, 10 | message: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(channel, message), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/rpush.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, ...elements: string[]) { 4 | return ['RPUSH', key, ...elements]; 5 | } 6 | 7 | export async function rpush( 8 | this: T, 9 | key: string, 10 | ...elements: string[] 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, ...elements), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/latency.graph.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | import type { RespLatencyEvent } from '../index.ts'; 4 | 5 | export function createCommand(event: RespLatencyEvent) { 6 | return ['LATENCY', 'GRAPH', event]; 7 | } 8 | 9 | export async function latencyGraph( 10 | this: T, 11 | event: RespLatencyEvent, 12 | ): Promise { 13 | return await executeCommand(this, createCommand(event), tryReplyToString); 14 | } 15 | -------------------------------------------------------------------------------- /sources/command/lindex.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, index: number) { 4 | return ['LINDEX', key, `${index}`]; 5 | } 6 | 7 | export async function lindex( 8 | this: T, 9 | key: string, 10 | index: number, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, index), 15 | tryReplyToStringOrNull, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/ltrim.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, start: number, stop: number) { 4 | return ['LTRIM', key, `${start}`, `${stop}`]; 5 | } 6 | 7 | export async function ltrim( 8 | this: T, 9 | key: string, 10 | start: number, 11 | stop: number, 12 | ) { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, start, stop), 16 | tryReplyOK, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/spublish.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(channel: string, message: string) { 4 | return ['SPUBLISH', channel, message]; 5 | } 6 | 7 | export async function spublish( 8 | this: T, 9 | channel: string, 10 | message: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(channel, message), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/bf.mexists.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, items: string[]) { 4 | return ['BF.MEXISTS', key, ...items]; 5 | } 6 | 7 | export async function bfMexists( 8 | this: T, 9 | key: string, 10 | items: string[], 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, items), 15 | tryReplyToNumberArray, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/lset.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, index: number, element: string) { 4 | return ['LSET', key, `${index}`, element]; 5 | } 6 | 7 | export async function lset( 8 | this: T, 9 | key: string, 10 | index: number, 11 | element: string, 12 | ) { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, index, element), 16 | tryReplyOK, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/incrbyfloat.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, increment: number) { 4 | return ['INCRBYFLOAT', key, `${increment}`]; 5 | } 6 | 7 | export async function incrbyfloat( 8 | this: T, 9 | key: string, 10 | increment: number, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, increment), 15 | tryReplyToNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/setnx.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { StringOrBuffer } from '../index.ts'; 4 | 5 | export function createCommand(key: string, value: StringOrBuffer) { 6 | return ['SETNX', key, value]; 7 | } 8 | 9 | export async function setnx( 10 | this: T, 11 | key: string, 12 | value: StringOrBuffer, 13 | ): Promise { 14 | return await executeCommand(this, createCommand(key, value), tryReplyNumber); 15 | } 16 | -------------------------------------------------------------------------------- /sources/command/xgroup.destroy.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, groupname: string) { 4 | return ['XGROUP', 'DESTROY', key, groupname]; 5 | } 6 | 7 | export async function xgroupDestroy( 8 | this: T, 9 | key: string, 10 | groupname: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, groupname), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/replconf.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(subcommand: string, ...arguments_: string[]) { 4 | return ['REPLCONF', subcommand, ...arguments_]; 5 | } 6 | 7 | export async function replconf( 8 | this: T, 9 | subcommand: string, 10 | ...arguments_: string[] 11 | ) { 12 | return await executeCommand( 13 | this, 14 | createCommand(subcommand, ...arguments_), 15 | tryReplyOK, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/sdiffstore.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(destination: string, keys: string[]) { 4 | return ['SDIFFSTORE', destination, ...keys]; 5 | } 6 | 7 | export async function sdiffstore( 8 | this: T, 9 | destination: string, 10 | keys: string[], 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(destination, keys), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/wait.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(numreplicas: number, timeout: number) { 4 | return ['WAIT', `${numreplicas}`, `${timeout}`]; 5 | } 6 | 7 | export async function wait( 8 | this: T, 9 | numreplicas: number, 10 | timeout: number, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(numreplicas, timeout), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/xack.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, group: string, ids: string[]) { 4 | return ['XACK', key, group, ...ids]; 5 | } 6 | 7 | export async function xack( 8 | this: T, 9 | key: string, 10 | group: string, 11 | ids: string[], 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, group, ids), 16 | tryReplyNumber, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/zcount.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, min: number, max: number) { 4 | return ['ZCOUNT', key, `${min}`, `${max}`]; 5 | } 6 | 7 | export async function zcount( 8 | this: T, 9 | key: string, 10 | min: number, 11 | max: number, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, min, max), 16 | tryReplyNumber, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/zlexcount.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, min: string, max: string) { 4 | return ['ZLEXCOUNT', key, min, max]; 5 | } 6 | 7 | export async function zlexcount( 8 | this: T, 9 | key: string, 10 | min: string, 11 | max: string, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, min, max), 16 | tryReplyNumber, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/acl.cat.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(category?: string) { 4 | const command = ['ACL', 'CAT']; 5 | 6 | if (category) { 7 | command.push(category); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function aclCat(this: T, category?: string) { 14 | return await executeCommand( 15 | this, 16 | createCommand(category), 17 | tryReplyToStringArray, 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /sources/command/function.flush.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(async?: boolean) { 4 | const command = ['FUNCTION', 'FLUSH']; 5 | 6 | if (async) { 7 | command.push('ASYNC'); 8 | } else { 9 | command.push('SYNC'); 10 | } 11 | 12 | return command; 13 | } 14 | 15 | export async function functionFlush(this: T, async?: boolean) { 16 | return await executeCommand(this, createCommand(async), tryReplyOK); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/sinterstore.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(destination: string, keys: string[]) { 4 | return ['SINTERSTORE', destination, ...keys]; 5 | } 6 | 7 | export async function sinterstore( 8 | this: T, 9 | destination: string, 10 | keys: string[], 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(destination, keys), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/sunionstore.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(destination: string, keys: string[]) { 4 | return ['SUNIONSTORE', destination, ...keys]; 5 | } 6 | 7 | export async function sunionstore( 8 | this: T, 9 | destination: string, 10 | keys: string[], 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(destination, keys), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/bf.loadchunk.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, iterator: number, data: Buffer) { 4 | return ['BF.LOADCHUNK', key, `${iterator}`, data]; 5 | } 6 | 7 | export async function bfLoadchunk( 8 | this: T, 9 | key: string, 10 | iterator: number, 11 | data: Buffer, 12 | ) { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, iterator, data), 16 | tryReplyOK, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/cf.loadchunk.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, iterator: number, data: Buffer) { 4 | return ['CF.LOADCHUNK', key, `${iterator}`, data]; 5 | } 6 | 7 | export async function cfLoadchunk( 8 | this: T, 9 | key: string, 10 | iterator: number, 11 | data: Buffer, 12 | ) { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, iterator, data), 16 | tryReplyOK, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/debug.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand } from './utils/index.ts'; 2 | 3 | import type { SolidisData } from '../index.ts'; 4 | 5 | export function createCommand(subcommand: string, ...parameters: string[]) { 6 | return ['DEBUG', subcommand, ...parameters]; 7 | } 8 | 9 | export async function debug( 10 | this: T, 11 | subcommand: string, 12 | ...parameters: string[] 13 | ): Promise { 14 | return await executeCommand(this, createCommand(subcommand, ...parameters)); 15 | } 16 | -------------------------------------------------------------------------------- /sources/command/ts.deleterule.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(sourceKey: string, destinationKey: string) { 4 | return ['TS.DELETERULE', sourceKey, destinationKey]; 5 | } 6 | 7 | export async function tsDeleterule( 8 | this: T, 9 | sourceKey: string, 10 | destinationKey: string, 11 | ) { 12 | return await executeCommand( 13 | this, 14 | createCommand(sourceKey, destinationKey), 15 | tryReplyOK, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/zadd.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, score: number, member: string) { 4 | return ['ZADD', key, `${score}`, member]; 5 | } 6 | 7 | export async function zadd( 8 | this: T, 9 | key: string, 10 | score: number, 11 | member: string, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, score, member), 16 | tryReplyNumber, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/lrem.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, count: number, element: string) { 4 | return ['LREM', key, `${count}`, element]; 5 | } 6 | 7 | export async function lrem( 8 | this: T, 9 | key: string, 10 | count: number, 11 | element: string, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, count, element), 16 | tryReplyNumber, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/zremrangebylex.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, min: string, max: string) { 4 | return ['ZREMRANGEBYLEX', key, min, max]; 5 | } 6 | 7 | export async function zremrangebylex( 8 | this: T, 9 | key: string, 10 | min: string, 11 | max: string, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, min, max), 16 | tryReplyNumber, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/getrange.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, start: number, end: number) { 4 | return ['GETRANGE', key, `${start}`, `${end}`]; 5 | } 6 | 7 | export async function getrange( 8 | this: T, 9 | key: string, 10 | start: number, 11 | end: number, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, start, end), 16 | tryReplyToString, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/hexpire.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, field: string, seconds: number) { 4 | return ['HEXPIRE', key, field, `${seconds}`]; 5 | } 6 | 7 | export async function hexpire( 8 | this: T, 9 | key: string, 10 | field: string, 11 | seconds: number, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, field, seconds), 16 | tryReplyNumber, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/zdiffstore.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(destination: string, keys: string[]) { 4 | return ['ZDIFFSTORE', destination, `${keys.length}`, ...keys]; 5 | } 6 | 7 | export async function zdiffstore( 8 | this: T, 9 | destination: string, 10 | keys: string[], 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(destination, keys), 15 | tryReplyNumber, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/config.get.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToConfigInfo } from './utils/index.ts'; 2 | 3 | import type { RespConfigInfo } from '../index.ts'; 4 | 5 | export function createCommand(parameter: string) { 6 | return ['CONFIG', 'GET', parameter]; 7 | } 8 | 9 | export async function configGet( 10 | this: T, 11 | parameter: string, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(parameter), 16 | tryReplyToConfigInfo, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/object.freq.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['OBJECT', 'FREQ', key]; 5 | } 6 | 7 | export async function objectFreq( 8 | this: T, 9 | key: string, 10 | ): Promise { 11 | return await executeCommand(this, createCommand(key), (reply, command) => { 12 | if (reply === null) { 13 | return null; 14 | } 15 | 16 | return tryReplyNumber(reply, command); 17 | }); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/rpoplpush.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand(source: string, destination: string) { 4 | return ['RPOPLPUSH', source, destination]; 5 | } 6 | 7 | export async function rpoplpush( 8 | this: T, 9 | source: string, 10 | destination: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(source, destination), 15 | tryReplyToStringOrNull, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/hincrby.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, field: string, increment: number) { 4 | return ['HINCRBY', key, field, `${increment}`]; 5 | } 6 | 7 | export async function hincrby( 8 | this: T, 9 | key: string, 10 | field: string, 11 | increment: number, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, field, increment), 16 | tryReplyNumber, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/json.del.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, path?: string) { 4 | const command = ['JSON.DEL', key]; 5 | 6 | if (path !== undefined) { 7 | command.push(path); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function jsonDel( 14 | this: T, 15 | key: string, 16 | path?: string, 17 | ): Promise { 18 | return await executeCommand(this, createCommand(key, path), tryReplyNumber); 19 | } 20 | -------------------------------------------------------------------------------- /sources/command/json.toggle.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, path: string) { 4 | return ['JSON.TOGGLE', key, path]; 5 | } 6 | 7 | export async function jsonToggle( 8 | this: T, 9 | key: string, 10 | path: string, 11 | ): Promise<(number | null)[]> { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, path), 15 | (reply, command) => tryReplyToNumberArray(reply, command, true), 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/lrange.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, start: number, stop: number) { 4 | return ['LRANGE', key, `${start}`, `${stop}`]; 5 | } 6 | 7 | export async function lrange( 8 | this: T, 9 | key: string, 10 | start: number, 11 | stop: number, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, start, stop), 16 | tryReplyToStringArray, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/zremrangebyscore.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, min: number, max: number) { 4 | return ['ZREMRANGEBYSCORE', key, `${min}`, `${max}`]; 5 | } 6 | 7 | export async function zremrangebyscore( 8 | this: T, 9 | key: string, 10 | min: number, 11 | max: number, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, min, max), 16 | tryReplyNumber, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/zrevrangebylex.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, max: string, min: string) { 4 | return ['ZREVRANGEBYLEX', key, max, min]; 5 | } 6 | 7 | export async function zrevrangebylex( 8 | this: T, 9 | key: string, 10 | max: string, 11 | min: string, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, max, min), 16 | tryReplyToStringArray, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/hexpireat.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, field: string, timestamp: number) { 4 | return ['HEXPIREAT', key, field, `${timestamp}`]; 5 | } 6 | 7 | export async function hexpireat( 8 | this: T, 9 | key: string, 10 | field: string, 11 | timestamp: number, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, field, timestamp), 16 | tryReplyNumber, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/json.clear.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, path?: string) { 4 | const command = ['JSON.CLEAR', key]; 5 | 6 | if (path !== undefined) { 7 | command.push(path); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function jsonClear( 14 | this: T, 15 | key: string, 16 | path?: string, 17 | ): Promise { 18 | return await executeCommand(this, createCommand(key, path), tryReplyNumber); 19 | } 20 | -------------------------------------------------------------------------------- /sources/command/zincrby.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, increment: number, member: string) { 4 | return ['ZINCRBY', key, `${increment}`, member]; 5 | } 6 | 7 | export async function zincrby( 8 | this: T, 9 | key: string, 10 | increment: number, 11 | member: string, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, increment, member), 16 | tryReplyNumber, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/zrevrange.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, start: number, stop: number) { 4 | return ['ZREVRANGE', key, `${start}`, `${stop}`]; 5 | } 6 | 7 | export async function zrevrange( 8 | this: T, 9 | key: string, 10 | start: number, 11 | stop: number, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, start, stop), 16 | tryReplyToStringArray, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /website/components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "new-york", 4 | "rsc": true, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "", 8 | "css": "app/globals.css", 9 | "baseColor": "neutral", 10 | "cssVariables": true, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "@/components", 15 | "utils": "@/lib/utils", 16 | "ui": "@/components/ui", 17 | "lib": "@/lib", 18 | "hooks": "@/hooks" 19 | }, 20 | "iconLibrary": "lucide" 21 | } -------------------------------------------------------------------------------- /sources/command/hmget.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, ...fields: string[]) { 4 | return ['HMGET', key, ...fields]; 5 | } 6 | 7 | export async function hmget( 8 | this: T, 9 | key: string, 10 | ...fields: string[] 11 | ): Promise<(string | null)[]> { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, ...fields), 15 | (reply, command) => tryReplyToStringArray(reply, command, true), 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/json.forget.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, path?: string) { 4 | const command = ['JSON.FORGET', key]; 5 | 6 | if (path !== undefined) { 7 | command.push(path); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function jsonForget( 14 | this: T, 15 | key: string, 16 | path?: string, 17 | ): Promise { 18 | return await executeCommand(this, createCommand(key, path), tryReplyNumber); 19 | } 20 | -------------------------------------------------------------------------------- /sources/command/json.mget.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(keys: string[], path: string) { 4 | return ['JSON.MGET', ...keys, path]; 5 | } 6 | 7 | export async function jsonMget( 8 | this: T, 9 | keys: string[], 10 | path: string, 11 | ): Promise> { 12 | return await executeCommand( 13 | this, 14 | createCommand(keys, path), 15 | (reply, command) => tryReplyToStringArray(reply, command, true), 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/object.idletime.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['OBJECT', 'IDLETIME', key]; 5 | } 6 | 7 | export async function objectIdletime( 8 | this: T, 9 | key: string, 10 | ): Promise { 11 | return await executeCommand(this, createCommand(key), (reply, command) => { 12 | if (reply === null) { 13 | return null; 14 | } 15 | 16 | return tryReplyNumber(reply, command); 17 | }); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/object.refcount.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string) { 4 | return ['OBJECT', 'REFCOUNT', key]; 5 | } 6 | 7 | export async function objectRefcount( 8 | this: T, 9 | key: string, 10 | ): Promise { 11 | return await executeCommand(this, createCommand(key), (reply, command) => { 12 | if (reply === null) { 13 | return null; 14 | } 15 | 16 | return tryReplyNumber(reply, command); 17 | }); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/command.getkeys.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(command: string, parameters: string[]) { 4 | return ['COMMAND', 'GETKEYS', command, ...parameters]; 5 | } 6 | 7 | export async function commandGetkeys( 8 | this: T, 9 | command: string, 10 | parameters: string[], 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(command, parameters), 15 | tryReplyToStringArray, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /sources/command/zrevrangebyscore.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, max: number, min: number) { 4 | return ['ZREVRANGEBYSCORE', key, `${max}`, `${min}`]; 5 | } 6 | 7 | export async function zrevrangebyscore( 8 | this: T, 9 | key: string, 10 | max: number, 11 | min: number, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, max, min), 16 | tryReplyToStringArray, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/hincrbyfloat.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, field: string, increment: number) { 4 | return ['HINCRBYFLOAT', key, field, `${increment}`]; 5 | } 6 | 7 | export async function hincrbyfloat( 8 | this: T, 9 | key: string, 10 | field: string, 11 | increment: number, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, field, increment), 16 | tryReplyToString, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/rpushx.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { StringOrBuffer } from '../index.ts'; 4 | 5 | export function createCommand(key: string, elements: StringOrBuffer[]) { 6 | return ['RPUSHX', key, ...elements]; 7 | } 8 | 9 | export async function rpushx( 10 | this: T, 11 | key: string, 12 | elements: StringOrBuffer[], 13 | ): Promise { 14 | return await executeCommand( 15 | this, 16 | createCommand(key, elements), 17 | tryReplyNumber, 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /sources/command/json.numincrby.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, path: string, value: number) { 4 | return ['JSON.NUMINCRBY', key, path, `${value}`]; 5 | } 6 | 7 | export async function jsonNumincrby( 8 | this: T, 9 | key: string, 10 | path: string, 11 | value: number, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, path, value), 16 | tryReplyToStringOrNull, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/json.nummultby.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, path: string, value: number) { 4 | return ['JSON.NUMMULTBY', key, path, `${value}`]; 5 | } 6 | 7 | export async function jsonNummultby( 8 | this: T, 9 | key: string, 10 | path: string, 11 | value: number, 12 | ): Promise { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, path, value), 16 | tryReplyToStringOrNull, 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/msetnx.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(keyValues: Record) { 4 | const command = ['MSETNX']; 5 | 6 | for (const [key, value] of Object.entries(keyValues)) { 7 | command.push(key, value); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function msetnx( 14 | this: T, 15 | keyValues: Record, 16 | ): Promise { 17 | return await executeCommand(this, createCommand(keyValues), tryReplyNumber); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/pubsub.channels.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(pattern?: string) { 4 | const command = ['PUBSUB', 'CHANNELS']; 5 | 6 | if (pattern) { 7 | command.push(pattern); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function pubsubChannels( 14 | this: T, 15 | pattern?: string, 16 | ): Promise { 17 | return await executeCommand( 18 | this, 19 | createCommand(pattern), 20 | tryReplyToStringArray, 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/smove.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | source: string, 5 | destination: string, 6 | member: string, 7 | ) { 8 | return ['SMOVE', source, destination, member]; 9 | } 10 | 11 | export async function smove( 12 | this: T, 13 | source: string, 14 | destination: string, 15 | member: string, 16 | ): Promise { 17 | return await executeCommand( 18 | this, 19 | createCommand(source, destination, member), 20 | tryReplyNumber, 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/hpexpire.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | field: string, 6 | milliseconds: number, 7 | ) { 8 | return ['HPEXPIRE', key, field, `${milliseconds}`]; 9 | } 10 | 11 | export async function hpexpire( 12 | this: T, 13 | key: string, 14 | field: string, 15 | milliseconds: number, 16 | ): Promise { 17 | return await executeCommand( 18 | this, 19 | createCommand(key, field, milliseconds), 20 | tryReplyNumber, 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/setbit.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { RespBit } from '../index.ts'; 4 | 5 | export function createCommand(key: string, offset: number, value: RespBit) { 6 | return ['SETBIT', key, `${offset}`, `${value}`]; 7 | } 8 | 9 | export async function setbit( 10 | this: T, 11 | key: string, 12 | offset: number, 13 | value: RespBit, 14 | ): Promise { 15 | return await executeCommand( 16 | this, 17 | createCommand(key, offset, value), 18 | tryReplyNumber, 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /sources/command/smismember.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | import type { StringOrBuffer } from '../index.ts'; 4 | 5 | export function createCommand(key: string, members: StringOrBuffer[]) { 6 | return ['SMISMEMBER', key, ...members]; 7 | } 8 | 9 | export async function smismember( 10 | this: T, 11 | key: string, 12 | members: StringOrBuffer[], 13 | ): Promise { 14 | return await executeCommand( 15 | this, 16 | createCommand(key, members), 17 | tryReplyToNumberArray, 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /sources/command/pubsub.shardchannels.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(pattern?: string) { 4 | const command = ['PUBSUB', 'SHARDCHANNELS']; 5 | 6 | if (pattern) { 7 | command.push(pattern); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function pubsubShardchannels( 14 | this: T, 15 | pattern?: string, 16 | ): Promise { 17 | return await executeCommand( 18 | this, 19 | createCommand(pattern), 20 | tryReplyToStringArray, 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/evalsha.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand } from './utils/index.ts'; 2 | 3 | import type { SolidisData } from '../index.ts'; 4 | 5 | export function createCommand( 6 | sha1: string, 7 | keys: string[], 8 | parameters: string[], 9 | ) { 10 | return ['EVALSHA', sha1, `${keys.length}`, ...keys, ...parameters]; 11 | } 12 | 13 | export async function evalsha( 14 | this: T, 15 | sha1: string, 16 | keys: string[], 17 | parameters: string[], 18 | ): Promise { 19 | return await executeCommand(this, createCommand(sha1, keys, parameters)); 20 | } 21 | -------------------------------------------------------------------------------- /sources/command/sintercard.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(keys: string[], limit?: number) { 4 | const command = ['SINTERCARD', `${keys.length}`, ...keys]; 5 | 6 | if (limit !== undefined) { 7 | command.push('LIMIT', `${limit}`); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function sintercard( 14 | this: T, 15 | keys: string[], 16 | limit?: number, 17 | ): Promise { 18 | return await executeCommand(this, createCommand(keys, limit), tryReplyNumber); 19 | } 20 | -------------------------------------------------------------------------------- /sources/command/acl.dryrun.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | username: string, 5 | command: string, 6 | parameters: string[], 7 | ) { 8 | return ['ACL', 'DRYRUN', username, command, ...parameters]; 9 | } 10 | 11 | export async function aclDryrun( 12 | this: T, 13 | username: string, 14 | command: string, 15 | parameters: string[], 16 | ) { 17 | return await executeCommand( 18 | this, 19 | createCommand(username, command, parameters), 20 | tryReplyToString, 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/eval.ro.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand } from './utils/index.ts'; 2 | 3 | import type { SolidisData } from '../index.ts'; 4 | 5 | export function createCommand( 6 | script: string, 7 | keys: string[], 8 | parameters: string[], 9 | ) { 10 | return ['EVAL_RO', script, `${keys.length}`, ...keys, ...parameters]; 11 | } 12 | 13 | export async function evalRo( 14 | this: T, 15 | script: string, 16 | keys: string[], 17 | parameters: string[], 18 | ): Promise { 19 | return await executeCommand(this, createCommand(script, keys, parameters)); 20 | } 21 | -------------------------------------------------------------------------------- /sources/command/eval.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand } from './utils/index.ts'; 2 | 3 | import type { SolidisData } from '../index.ts'; 4 | 5 | export function createCommand( 6 | script: string, 7 | keys: string[], 8 | parameters: string[], 9 | ) { 10 | return ['EVAL', script, `${keys.length}`, ...keys, ...parameters]; 11 | } 12 | 13 | export async function evaluate( 14 | this: T, 15 | script: string, 16 | keys: string[], 17 | parameters: string[], 18 | ): Promise { 19 | return await executeCommand(this, createCommand(script, keys, parameters)); 20 | } 21 | -------------------------------------------------------------------------------- /sources/command/module.load.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(path: string, parameters?: string[]) { 4 | const command = ['MODULE', 'LOAD', path]; 5 | 6 | if (parameters?.length) { 7 | command.push(...parameters); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function moduleLoad( 14 | this: T, 15 | path: string, 16 | parameters?: string[], 17 | ) { 18 | return await executeCommand( 19 | this, 20 | createCommand(path, parameters), 21 | tryReplyOK, 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "editor.defaultFormatter": "biomejs.biome", 4 | "[javascript][typescript][json]": { 5 | "editor.defaultFormatter": "biomejs.biome" 6 | }, 7 | "editor.codeActionsOnSave": { 8 | "quickfix.biome": "explicit", 9 | "source.organizeImports.biome": "explicit" 10 | }, 11 | "typescript.preferences.importModuleSpecifierEnding": "js", 12 | "typescript.preferences.quoteStyle": "single", 13 | "typescript.preferences.includePackageJsonAutoImports": "on", 14 | "typescript.tsdk": "node_modules/typescript/lib" 15 | } 16 | -------------------------------------------------------------------------------- /sources/command/evalsha.ro.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand } from './utils/index.ts'; 2 | 3 | import type { SolidisData } from '../index.ts'; 4 | 5 | export function createCommand( 6 | sha1: string, 7 | keys: string[], 8 | parameters: string[], 9 | ) { 10 | return ['EVALSHA_RO', sha1, `${keys.length}`, ...keys, ...parameters]; 11 | } 12 | 13 | export async function evalshaRo( 14 | this: T, 15 | sha1: string, 16 | keys: string[], 17 | parameters: string[], 18 | ): Promise { 19 | return await executeCommand(this, createCommand(sha1, keys, parameters)); 20 | } 21 | -------------------------------------------------------------------------------- /sources/command/json.mset.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | items: Array<{ key: string; path: string; value: string }>, 5 | ) { 6 | const command = ['JSON.MSET']; 7 | 8 | for (const { key, path, value } of items) { 9 | command.push(key, path, value); 10 | } 11 | 12 | return command; 13 | } 14 | 15 | export async function jsonMset( 16 | this: T, 17 | items: Array<{ key: string; path: string; value: string }>, 18 | ) { 19 | return await executeCommand(this, createCommand(items), tryReplyOK); 20 | } 21 | -------------------------------------------------------------------------------- /sources/command/latency.reset.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { RespLatencyEvent } from '../index.ts'; 4 | 5 | export function createCommand(events?: RespLatencyEvent[]) { 6 | const command = ['LATENCY', 'RESET']; 7 | 8 | if (events?.length) { 9 | command.push(...events); 10 | } 11 | 12 | return command; 13 | } 14 | 15 | export async function latencyReset( 16 | this: T, 17 | events?: RespLatencyEvent[], 18 | ): Promise { 19 | return await executeCommand(this, createCommand(events), tryReplyNumber); 20 | } 21 | -------------------------------------------------------------------------------- /sources/command/setex.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { StringOrBuffer } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | seconds: number, 8 | value: StringOrBuffer, 9 | ) { 10 | return ['SETEX', key, `${seconds}`, value]; 11 | } 12 | 13 | export async function setex( 14 | this: T, 15 | key: string, 16 | seconds: number, 17 | value: StringOrBuffer, 18 | ) { 19 | return await executeCommand( 20 | this, 21 | createCommand(key, seconds, value), 22 | tryReplyOK, 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /sources/command/ts.del.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | fromTimestamp: number, 6 | toTimestamp: number, 7 | ) { 8 | return ['TS.DEL', key, `${fromTimestamp}`, `${toTimestamp}`]; 9 | } 10 | 11 | export async function tsDel( 12 | this: T, 13 | key: string, 14 | fromTimestamp: number, 15 | toTimestamp: number, 16 | ): Promise { 17 | return await executeCommand( 18 | this, 19 | createCommand(key, fromTimestamp, toTimestamp), 20 | tryReplyNumber, 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/hset.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { StringOrBuffer } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | field: string, 8 | value: StringOrBuffer, 9 | ) { 10 | return ['HSET', key, field, value]; 11 | } 12 | 13 | export async function hset( 14 | this: T, 15 | key: string, 16 | field: string, 17 | value: StringOrBuffer, 18 | ): Promise { 19 | return await executeCommand( 20 | this, 21 | createCommand(key, field, value), 22 | tryReplyNumber, 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /sources/command/json.arrappend.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, path: string, ...values: string[]) { 4 | return ['JSON.ARRAPPEND', key, path, ...values]; 5 | } 6 | 7 | export async function jsonArrappend( 8 | this: T, 9 | key: string, 10 | path: string, 11 | ...values: string[] 12 | ): Promise<(number | null)[]> { 13 | return await executeCommand( 14 | this, 15 | createCommand(key, path, ...values), 16 | (reply, command) => tryReplyToNumberArray(reply, command, true), 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /sources/command/zrank.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, member: string) { 4 | return ['ZRANK', key, member]; 5 | } 6 | 7 | export async function zrank( 8 | this: T, 9 | key: string, 10 | member: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, member), 15 | (reply, command) => { 16 | if (reply === null) { 17 | return null; 18 | } 19 | 20 | return tryReplyNumber(reply, command); 21 | }, 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /sources/command/zscore.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, member: string) { 4 | return ['ZSCORE', key, member]; 5 | } 6 | 7 | export async function zscore( 8 | this: T, 9 | key: string, 10 | member: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, member), 15 | (reply, command) => { 16 | if (reply === null) { 17 | return null; 18 | } 19 | 20 | return tryReplyNumber(reply, command); 21 | }, 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /sources/command/hpexpireat.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | field: string, 6 | millisecondsTimestamp: number, 7 | ) { 8 | return ['HPEXPIREAT', key, field, `${millisecondsTimestamp}`]; 9 | } 10 | 11 | export async function hpexpireat( 12 | this: T, 13 | key: string, 14 | field: string, 15 | millisecondsTimestamp: number, 16 | ): Promise { 17 | return await executeCommand( 18 | this, 19 | createCommand(key, field, millisecondsTimestamp), 20 | tryReplyNumber, 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/hsetnx.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { StringOrBuffer } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | field: string, 8 | value: StringOrBuffer, 9 | ) { 10 | return ['HSETNX', key, field, value]; 11 | } 12 | 13 | export async function hsetnx( 14 | this: T, 15 | key: string, 16 | field: string, 17 | value: StringOrBuffer, 18 | ): Promise { 19 | return await executeCommand( 20 | this, 21 | createCommand(key, field, value), 22 | tryReplyNumber, 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /sources/command/xgroup.delconsumer.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | groupname: string, 6 | consumername: string, 7 | ) { 8 | return ['XGROUP', 'DELCONSUMER', key, groupname, consumername]; 9 | } 10 | 11 | export async function xgroupDelconsumer( 12 | this: T, 13 | key: string, 14 | groupname: string, 15 | consumername: string, 16 | ): Promise { 17 | return await executeCommand( 18 | this, 19 | createCommand(key, groupname, consumername), 20 | tryReplyNumber, 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/brpoplpush.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | source: string, 5 | destination: string, 6 | timeout: number, 7 | ) { 8 | return ['BRPOPLPUSH', source, destination, `${timeout}`]; 9 | } 10 | 11 | export async function brpoplpush( 12 | this: T, 13 | source: string, 14 | destination: string, 15 | timeout: number, 16 | ): Promise { 17 | return await executeCommand( 18 | this, 19 | createCommand(source, destination, timeout), 20 | tryReplyToStringOrNull, 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/function.load.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand(code: string, replace: boolean) { 4 | const command = ['FUNCTION', 'LOAD']; 5 | 6 | if (replace) { 7 | command.push('REPLACE'); 8 | } 9 | 10 | command.push(code); 11 | 12 | return command; 13 | } 14 | 15 | export async function functionLoad( 16 | this: T, 17 | code: string, 18 | replace = false, 19 | ): Promise { 20 | return await executeCommand( 21 | this, 22 | createCommand(code, replace), 23 | tryReplyToString, 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /sources/command/mset.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { StringOrBuffer } from '../index.ts'; 4 | 5 | export function createCommand(mapping: Record) { 6 | const command: StringOrBuffer[] = ['MSET']; 7 | 8 | for (const [key, value] of Object.entries(mapping)) { 9 | command.push(key, value); 10 | } 11 | 12 | return command; 13 | } 14 | 15 | export async function mset( 16 | this: T, 17 | mapping: Record, 18 | ) { 19 | return await executeCommand(this, createCommand(mapping), tryReplyOK); 20 | } 21 | -------------------------------------------------------------------------------- /sources/command/psetex.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { StringOrBuffer } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | milliseconds: number, 8 | value: StringOrBuffer, 9 | ) { 10 | return ['PSETEX', key, `${milliseconds}`, value]; 11 | } 12 | 13 | export async function psetex( 14 | this: T, 15 | key: string, 16 | milliseconds: number, 17 | value: StringOrBuffer, 18 | ) { 19 | return await executeCommand( 20 | this, 21 | createCommand(key, milliseconds, value), 22 | tryReplyOK, 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /sources/command/zrevrank.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, member: string) { 4 | return ['ZREVRANK', key, member]; 5 | } 6 | 7 | export async function zrevrank( 8 | this: T, 9 | key: string, 10 | member: string, 11 | ): Promise { 12 | return await executeCommand( 13 | this, 14 | createCommand(key, member), 15 | (reply, command) => { 16 | if (reply === null) { 17 | return null; 18 | } 19 | 20 | return tryReplyNumber(reply, command); 21 | }, 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /sources/command/json.merge.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, value: string, path?: string) { 4 | const command = ['JSON.MERGE', key]; 5 | 6 | if (path !== undefined) { 7 | command.push(path); 8 | } 9 | 10 | command.push(value); 11 | 12 | return command; 13 | } 14 | 15 | export async function jsonMerge( 16 | this: T, 17 | key: string, 18 | value: string, 19 | path?: string, 20 | ) { 21 | return await executeCommand( 22 | this, 23 | createCommand(key, value, path), 24 | tryReplyOK, 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /sources/command/xgroup.createconsumer.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | groupname: string, 6 | consumername: string, 7 | ) { 8 | return ['XGROUP', 'CREATECONSUMER', key, groupname, consumername]; 9 | } 10 | 11 | export async function xgroupCreateconsumer( 12 | this: T, 13 | key: string, 14 | groupname: string, 15 | consumername: string, 16 | ): Promise { 17 | return await executeCommand( 18 | this, 19 | createCommand(key, groupname, consumername), 20 | tryReplyNumber, 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/setrange.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { StringOrBuffer } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | offset: number, 8 | value: StringOrBuffer, 9 | ) { 10 | return ['SETRANGE', key, `${offset}`, value]; 11 | } 12 | 13 | export async function setrange( 14 | this: T, 15 | key: string, 16 | offset: number, 17 | value: StringOrBuffer, 18 | ): Promise { 19 | return await executeCommand( 20 | this, 21 | createCommand(key, offset, value), 22 | tryReplyNumber, 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /sources/command/ts.alter.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildTimeSeriesCommand, 3 | executeCommand, 4 | tryReplyOK, 5 | } from './utils/index.ts'; 6 | 7 | import type { CommandTimeSeriesAlterOptions } from '../index.ts'; 8 | 9 | export function createCommand( 10 | key: string, 11 | options: CommandTimeSeriesAlterOptions, 12 | ) { 13 | return buildTimeSeriesCommand(['TS.ALTER', key], options); 14 | } 15 | 16 | export async function tsAlter( 17 | this: T, 18 | key: string, 19 | options: CommandTimeSeriesAlterOptions = {}, 20 | ) { 21 | return await executeCommand(this, createCommand(key, options), tryReplyOK); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/ts.create.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildTimeSeriesCommand, 3 | executeCommand, 4 | tryReplyOK, 5 | } from './utils/index.ts'; 6 | 7 | import type { CommandTimeSeriesCreateOptions } from '../index.ts'; 8 | 9 | export function createCommand( 10 | key: string, 11 | options: CommandTimeSeriesCreateOptions, 12 | ) { 13 | return buildTimeSeriesCommand(['TS.CREATE', key], options); 14 | } 15 | 16 | export async function tsCreate( 17 | this: T, 18 | key: string, 19 | options: CommandTimeSeriesCreateOptions = {}, 20 | ) { 21 | return await executeCommand(this, createCommand(key, options), tryReplyOK); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/fcall.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand } from './utils/index.ts'; 2 | 3 | import type { SolidisData } from '../index.ts'; 4 | 5 | export function createCommand( 6 | functionName: string, 7 | keys: string[], 8 | parameters: string[], 9 | ) { 10 | return ['FCALL', functionName, `${keys.length}`, ...keys, ...parameters]; 11 | } 12 | 13 | export async function fcall( 14 | this: T, 15 | functionName: string, 16 | keys: string[], 17 | parameters: string[], 18 | ): Promise { 19 | return await executeCommand( 20 | this, 21 | createCommand(functionName, keys, parameters), 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /sources/command/fcall.ro.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand } from './utils/index.ts'; 2 | 3 | import type { SolidisData } from '../index.ts'; 4 | 5 | export function createCommand( 6 | functionName: string, 7 | keys: string[], 8 | parameters: string[], 9 | ) { 10 | return ['FCALL_RO', functionName, `${keys.length}`, ...keys, ...parameters]; 11 | } 12 | 13 | export async function fcallRo( 14 | this: T, 15 | functionName: string, 16 | keys: string[], 17 | parameters: string[], 18 | ): Promise { 19 | return await executeCommand( 20 | this, 21 | createCommand(functionName, keys, parameters), 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /sources/command/json.arrlen.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, path?: string) { 4 | const command = ['JSON.ARRLEN', key]; 5 | 6 | if (path !== undefined) { 7 | command.push(path); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function jsonArrlen( 14 | this: T, 15 | key: string, 16 | path?: string, 17 | ): Promise<(number | null)[]> { 18 | return await executeCommand( 19 | this, 20 | createCommand(key, path), 21 | (reply, command) => tryReplyToNumberArray(reply, command, true), 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /sources/command/json.objkeys.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, path?: string) { 4 | const command = ['JSON.OBJKEYS', key]; 5 | 6 | if (path !== undefined) { 7 | command.push(path); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function jsonObjkeys( 14 | this: T, 15 | key: string, 16 | path?: string, 17 | ): Promise<(string | null)[]> { 18 | return await executeCommand( 19 | this, 20 | createCommand(key, path), 21 | (reply, command) => tryReplyToStringArray(reply, command, true), 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /sources/command/json.objlen.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, path?: string) { 4 | const command = ['JSON.OBJLEN', key]; 5 | 6 | if (path !== undefined) { 7 | command.push(path); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function jsonObjlen( 14 | this: T, 15 | key: string, 16 | path?: string, 17 | ): Promise<(number | null)[]> { 18 | return await executeCommand( 19 | this, 20 | createCommand(key, path), 21 | (reply, command) => tryReplyToNumberArray(reply, command, true), 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /sources/command/json.strlen.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, path?: string) { 4 | const command = ['JSON.STRLEN', key]; 5 | 6 | if (path !== undefined) { 7 | command.push(path); 8 | } 9 | 10 | return command; 11 | } 12 | 13 | export async function jsonStrlen( 14 | this: T, 15 | key: string, 16 | path?: string, 17 | ): Promise<(number | null)[]> { 18 | return await executeCommand( 19 | this, 20 | createCommand(key, path), 21 | (reply, command) => tryReplyToNumberArray(reply, command, true), 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /sources/command/script.flush.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { CommandScriptFlushOptions } from '../index.ts'; 4 | 5 | export function createCommand(options?: CommandScriptFlushOptions) { 6 | const command = ['SCRIPT', 'FLUSH']; 7 | 8 | if (options?.sync) { 9 | command.push('SYNC'); 10 | } else if (options?.async) { 11 | command.push('ASYNC'); 12 | } 13 | 14 | return command; 15 | } 16 | 17 | export async function scriptFlush( 18 | this: T, 19 | options?: CommandScriptFlushOptions, 20 | ) { 21 | return await executeCommand(this, createCommand(options), tryReplyOK); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/xadd.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | import type { StringOrBuffer } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | id: string, 8 | fields: Record, 9 | ) { 10 | return ['XADD', key, id, ...Object.entries(fields).flat()]; 11 | } 12 | 13 | export async function xadd( 14 | this: T, 15 | key: string, 16 | id: string, 17 | fields: Record, 18 | ): Promise { 19 | return await executeCommand( 20 | this, 21 | createCommand(key, id, fields), 22 | tryReplyToString, 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /sources/command/json.resp.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyArray } from './utils/index.ts'; 2 | 3 | import type { SolidisData } from '../index.ts'; 4 | 5 | export function createCommand(key: string, path?: string) { 6 | const command = ['JSON.RESP', key]; 7 | 8 | if (path !== undefined) { 9 | command.push(path); 10 | } 11 | 12 | return command; 13 | } 14 | 15 | export async function jsonResp( 16 | this: T, 17 | key: string, 18 | path?: string, 19 | ): Promise { 20 | return await executeCommand( 21 | this, 22 | createCommand(key, path), 23 | (reply, command) => tryReplyArray(reply, command), 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /sources/command/get.buffer.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | newCommandError, 4 | UnexpectedReplyPrefix, 5 | } from './utils/index.ts'; 6 | 7 | export function createCommand(key: string) { 8 | return ['GET', key]; 9 | } 10 | 11 | export async function getBuffer( 12 | this: T, 13 | key: string, 14 | ): Promise { 15 | return await executeCommand(this, createCommand(key), (reply, command) => { 16 | if (reply === null) { 17 | return null; 18 | } 19 | 20 | if (reply instanceof Buffer) { 21 | return reply; 22 | } 23 | 24 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 25 | }); 26 | } 27 | -------------------------------------------------------------------------------- /sources/command/auth.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand(username?: string, password?: string) { 4 | const commands = ['AUTH']; 5 | 6 | if (username && password) { 7 | commands.push(username, password); 8 | } else if (password) { 9 | commands.push('default', password); 10 | } else if (username) { 11 | commands.push(username); 12 | } 13 | 14 | return commands; 15 | } 16 | 17 | export async function auth(this: T, username?: string, password?: string) { 18 | return await executeCommand( 19 | this, 20 | createCommand(username, password), 21 | tryReplyOK, 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /sources/command/module.list.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | newCommandError, 4 | tryReplyToModuleInfo, 5 | UnexpectedReplyPrefix, 6 | } from './utils/index.ts'; 7 | 8 | import type { RespModuleInfo } from '../index.ts'; 9 | 10 | export function createCommand() { 11 | return ['MODULE', 'LIST']; 12 | } 13 | 14 | export async function moduleList(this: T): Promise { 15 | return await executeCommand(this, createCommand(), (reply, command) => { 16 | if (!Array.isArray(reply)) { 17 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 18 | } 19 | 20 | return reply.map(tryReplyToModuleInfo); 21 | }); 22 | } 23 | -------------------------------------------------------------------------------- /sources/command/json.arrinsert.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | path: string, 6 | index: number, 7 | ...values: string[] 8 | ) { 9 | return ['JSON.ARRINSERT', key, path, `${index}`, ...values]; 10 | } 11 | 12 | export async function jsonArrinsert( 13 | this: T, 14 | key: string, 15 | path: string, 16 | index: number, 17 | ...values: string[] 18 | ): Promise<(number | null)[]> { 19 | return await executeCommand( 20 | this, 21 | createCommand(key, path, index, ...values), 22 | (reply, command) => tryReplyToNumberArray(reply, command, true), 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /sources/command/expireat.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | timestamp: number, 6 | options?: { notExists?: boolean }, 7 | ) { 8 | const command = ['EXPIREAT', key, `${timestamp}`]; 9 | 10 | if (options?.notExists) { 11 | command.push('NX'); 12 | } 13 | 14 | return command; 15 | } 16 | 17 | export async function expireat( 18 | this: T, 19 | key: string, 20 | timestamp: number, 21 | options?: { notExists?: boolean }, 22 | ): Promise { 23 | return await executeCommand( 24 | this, 25 | createCommand(key, timestamp, options), 26 | tryReplyNumber, 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /sources/command/xrange.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | tryReplyArray, 4 | tryReplyToStreamEntry, 5 | } from './utils/index.ts'; 6 | 7 | import type { RespStreamEntry } from '../index.ts'; 8 | 9 | export function createCommand(key: string, start: string, end: string) { 10 | return ['XRANGE', key, start, end]; 11 | } 12 | 13 | export async function xrange( 14 | this: T, 15 | key: string, 16 | start: string, 17 | end: string, 18 | ): Promise { 19 | return await executeCommand( 20 | this, 21 | createCommand(key, start, end), 22 | (reply, command) => { 23 | return tryReplyArray(reply, command).map(tryReplyToStreamEntry); 24 | }, 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /sources/command/client.pause.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { CommandClientPauseOptions } from '../index.ts'; 4 | 5 | export function createCommand( 6 | timeout: number, 7 | options?: CommandClientPauseOptions, 8 | ) { 9 | const command = ['CLIENT', 'PAUSE', `${timeout}`]; 10 | 11 | if (options?.mode) { 12 | command.push(options.mode); 13 | } 14 | 15 | return command; 16 | } 17 | 18 | export async function clientPause( 19 | this: T, 20 | timeout: number, 21 | options?: CommandClientPauseOptions, 22 | ) { 23 | return await executeCommand( 24 | this, 25 | createCommand(timeout, options), 26 | tryReplyOK, 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /sources/command/ts.madd.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | samples: Array<{ timestamp: number; value: number }>, 6 | ) { 7 | const command = ['TS.MADD']; 8 | 9 | for (const sample of samples) { 10 | command.push(key, `${sample.timestamp}`, `${sample.value}`); 11 | } 12 | 13 | return command; 14 | } 15 | 16 | export async function tsMadd( 17 | this: T, 18 | key: string, 19 | samples: Array<{ timestamp: number; value: number }>, 20 | ): Promise { 21 | return await executeCommand( 22 | this, 23 | createCommand(key, samples), 24 | tryReplyToNumberArray, 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /sources/command/json.strappend.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, value: string, path?: string) { 4 | const command = ['JSON.STRAPPEND', key]; 5 | 6 | if (path !== undefined) { 7 | command.push(path); 8 | } 9 | 10 | command.push(value); 11 | 12 | return command; 13 | } 14 | 15 | export async function jsonStrappend( 16 | this: T, 17 | key: string, 18 | value: string, 19 | path?: string, 20 | ): Promise<(number | null)[]> { 21 | return await executeCommand( 22 | this, 23 | createCommand(key, value, path), 24 | (reply, command) => tryReplyToNumberArray(reply, command, true), 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /sources/command/linsert.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { CommandBeforeOrAfterOption } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | position: CommandBeforeOrAfterOption, 8 | pivot: string, 9 | element: string, 10 | ) { 11 | return ['LINSERT', key, position, pivot, element]; 12 | } 13 | 14 | export async function linsert( 15 | this: T, 16 | key: string, 17 | position: CommandBeforeOrAfterOption, 18 | pivot: string, 19 | element: string, 20 | ): Promise { 21 | return await executeCommand( 22 | this, 23 | createCommand(key, position, pivot, element), 24 | tryReplyNumber, 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /sources/command/json.arrpop.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | export function createCommand(key: string, path?: string, index?: number) { 4 | const command = ['JSON.ARRPOP', key]; 5 | 6 | if (path !== undefined) { 7 | command.push(path); 8 | 9 | if (index !== undefined) { 10 | command.push(`${index}`); 11 | } 12 | } 13 | 14 | return command; 15 | } 16 | 17 | export async function jsonArrpop( 18 | this: T, 19 | key: string, 20 | path?: string, 21 | index?: number, 22 | ): Promise<(string | null)[]> { 23 | return await executeCommand( 24 | this, 25 | createCommand(key, path, index), 26 | tryReplyToStringArray, 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /website/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2017", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "noEmit": true, 9 | "esModuleInterop": true, 10 | "module": "esnext", 11 | "moduleResolution": "bundler", 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "jsx": "preserve", 15 | "incremental": true, 16 | "plugins": [ 17 | { 18 | "name": "next" 19 | } 20 | ], 21 | "paths": { 22 | "@/*": ["./*"] 23 | } 24 | }, 25 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 26 | "exclude": ["node_modules"] 27 | } 28 | -------------------------------------------------------------------------------- /sources/command/pexpire.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { CommandExpireMode } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | milliseconds: number, 8 | mode?: CommandExpireMode, 9 | ) { 10 | const command = ['PEXPIRE', key, `${milliseconds}`]; 11 | 12 | if (mode) { 13 | command.push(mode); 14 | } 15 | 16 | return command; 17 | } 18 | 19 | export async function pexpire( 20 | this: T, 21 | key: string, 22 | milliseconds: number, 23 | mode?: CommandExpireMode, 24 | ): Promise { 25 | return await executeCommand( 26 | this, 27 | createCommand(key, milliseconds, mode), 28 | tryReplyNumber, 29 | ); 30 | } 31 | -------------------------------------------------------------------------------- /sources/command/xgroup.setid.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | groupname: string, 6 | id: string, 7 | entriesRead?: number, 8 | ) { 9 | const command = ['XGROUP', 'SETID', key, groupname, id]; 10 | 11 | if (entriesRead !== undefined) { 12 | command.push('ENTRIESREAD', `${entriesRead}`); 13 | } 14 | 15 | return command; 16 | } 17 | 18 | export async function xgroupSetid( 19 | this: T, 20 | key: string, 21 | groupname: string, 22 | id: string, 23 | entriesRead?: number, 24 | ) { 25 | return await executeCommand( 26 | this, 27 | createCommand(key, groupname, id, entriesRead), 28 | tryReplyOK, 29 | ); 30 | } 31 | -------------------------------------------------------------------------------- /sources/command/json.arrtrim.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | import type { CommandJsonArrTrimOptions } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | path: string, 8 | options: CommandJsonArrTrimOptions, 9 | ) { 10 | return ['JSON.ARRTRIM', key, path, `${options.start}`, `${options.stop}`]; 11 | } 12 | 13 | export async function jsonArrtrim( 14 | this: T, 15 | key: string, 16 | path: string, 17 | options: CommandJsonArrTrimOptions, 18 | ): Promise<(number | null)[]> { 19 | return await executeCommand( 20 | this, 21 | createCommand(key, path, options), 22 | (reply, command) => tryReplyToNumberArray(reply, command, true), 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /sources/command/lolwut.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | version?: number, 5 | ...optionalArguments: string[] 6 | ) { 7 | const command = ['LOLWUT']; 8 | 9 | if (version !== undefined) { 10 | command.push('VERSION', `${version}`); 11 | } 12 | 13 | if (optionalArguments.length) { 14 | command.push(...optionalArguments); 15 | } 16 | 17 | return command; 18 | } 19 | 20 | export async function lolwut( 21 | this: T, 22 | version?: number, 23 | ...optionalArguments: string[] 24 | ): Promise { 25 | return await executeCommand( 26 | this, 27 | createCommand(version, ...optionalArguments), 28 | tryReplyToString, 29 | ); 30 | } 31 | -------------------------------------------------------------------------------- /sources/command/time.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | newCommandError, 4 | UnexpectedReplyPrefix, 5 | } from './utils/index.ts'; 6 | 7 | export function createCommand() { 8 | return ['TIME']; 9 | } 10 | 11 | export async function time( 12 | this: T, 13 | ): Promise<[seconds: number, microseconds: number]> { 14 | return await executeCommand(this, createCommand(), (reply, command) => { 15 | if (Array.isArray(reply) && reply.length === 2) { 16 | const [seconds, microseconds] = reply; 17 | 18 | if (typeof seconds === 'number' && typeof microseconds === 'number') { 19 | return [seconds, microseconds]; 20 | } 21 | } 22 | 23 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 24 | }); 25 | } 26 | -------------------------------------------------------------------------------- /website/components/language-switcher.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import { useI18n } from "@/lib/i18n-context" 4 | import { Button } from "@/components/ui/button" 5 | import { Languages } from "lucide-react" 6 | 7 | export function LanguageSwitcher() { 8 | const { locale, setLocale } = useI18n() 9 | 10 | const toggleLanguage = () => { 11 | setLocale(locale === 'en' ? 'ko' : 'en') 12 | } 13 | 14 | return ( 15 | 25 | ) 26 | } 27 | -------------------------------------------------------------------------------- /sources/command/ts.decrby.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildTimeSeriesCommand, 3 | executeCommand, 4 | tryReplyNumber, 5 | } from './utils/index.ts'; 6 | 7 | import type { CommandTimeSeriesIncrDecrOptions } from '../index.ts'; 8 | 9 | export function createCommand( 10 | key: string, 11 | decrement: number, 12 | options: CommandTimeSeriesIncrDecrOptions, 13 | ) { 14 | return buildTimeSeriesCommand(['TS.DECRBY', key, `${decrement}`], options); 15 | } 16 | 17 | export async function tsDecrby( 18 | this: T, 19 | key: string, 20 | decrement: number, 21 | options: CommandTimeSeriesIncrDecrOptions = {}, 22 | ): Promise { 23 | return await executeCommand( 24 | this, 25 | createCommand(key, decrement, options), 26 | tryReplyNumber, 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /sources/command/ts.incrby.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildTimeSeriesCommand, 3 | executeCommand, 4 | tryReplyNumber, 5 | } from './utils/index.ts'; 6 | 7 | import type { CommandTimeSeriesIncrDecrOptions } from '../index.ts'; 8 | 9 | export function createCommand( 10 | key: string, 11 | increment: number, 12 | options: CommandTimeSeriesIncrDecrOptions, 13 | ) { 14 | return buildTimeSeriesCommand(['TS.INCRBY', key, `${increment}`], options); 15 | } 16 | 17 | export async function tsIncrby( 18 | this: T, 19 | key: string, 20 | increment: number, 21 | options: CommandTimeSeriesIncrDecrOptions = {}, 22 | ): Promise { 23 | return await executeCommand( 24 | this, 25 | createCommand(key, increment, options), 26 | tryReplyNumber, 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /sources/command/bitop.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { RespBitOperation } from '../index.ts'; 4 | 5 | export function createCommand( 6 | operation: RespBitOperation, 7 | destkey: string, 8 | keys: string[], 9 | ) { 10 | if (operation === 'NOT' && keys.length !== 1) { 11 | throw new Error('BITOP NOT accepts exactly one source key'); 12 | } 13 | 14 | return ['BITOP', operation, destkey, ...keys]; 15 | } 16 | 17 | export async function bitop( 18 | this: T, 19 | operation: RespBitOperation, 20 | destkey: string, 21 | keys: string[], 22 | ): Promise { 23 | return await executeCommand( 24 | this, 25 | createCommand(operation, destkey, keys), 26 | tryReplyNumber, 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /sources/command/getset.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | import type { StringOrBuffer } from '../index.ts'; 4 | 5 | export function createCommand(key: string, value: StringOrBuffer) { 6 | return ['GETSET', key, value]; 7 | } 8 | 9 | /** 10 | * @deprecated 11 | * @see https://redis.io/docs/latest/commands/getset/ 12 | * As of Redis version 6.2.0, this command is regarded as deprecated. 13 | * Use `set` with the `returnOldValue` option instead. 14 | */ 15 | export async function getset( 16 | this: T, 17 | key: string, 18 | value: StringOrBuffer, 19 | ): Promise { 20 | return await executeCommand( 21 | this, 22 | createCommand(key, value), 23 | tryReplyToStringOrNull, 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /sources/command/pexpireat.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { CommandExpireMode } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | millisecondsTimestamp: number, 8 | mode?: CommandExpireMode, 9 | ) { 10 | const command = ['PEXPIREAT', key, `${millisecondsTimestamp}`]; 11 | 12 | if (mode) { 13 | command.push(mode); 14 | } 15 | 16 | return command; 17 | } 18 | 19 | export async function pexpireat( 20 | this: T, 21 | key: string, 22 | millisecondsTimestamp: number, 23 | mode?: CommandExpireMode, 24 | ): Promise { 25 | return await executeCommand( 26 | this, 27 | createCommand(key, millisecondsTimestamp, mode), 28 | tryReplyNumber, 29 | ); 30 | } 31 | -------------------------------------------------------------------------------- /sources/command/cf.mexists.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | newCommandError, 4 | tryReplyToBoolean, 5 | UnexpectedReplyPrefix, 6 | } from './utils/index.ts'; 7 | 8 | export function createCommand(key: string, items: string[]) { 9 | return ['CF.MEXISTS', key, ...items]; 10 | } 11 | 12 | export async function cfMexists( 13 | this: T, 14 | key: string, 15 | items: string[], 16 | ): Promise<(number | boolean)[]> { 17 | return await executeCommand( 18 | this, 19 | createCommand(key, items), 20 | (reply, command) => { 21 | if (Array.isArray(reply)) { 22 | return reply.map((value) => tryReplyToBoolean(value, command)); 23 | } 24 | 25 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 26 | }, 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /sources/command/pipeline.ts: -------------------------------------------------------------------------------- 1 | import { 2 | guard, 3 | newCommandError, 4 | UnexpectedReplyPrefix, 5 | } from './utils/index.ts'; 6 | 7 | import type { SolidisData, StringOrBuffer } from '../index.ts'; 8 | 9 | export async function pipeline( 10 | this: T, 11 | commands: StringOrBuffer[][], 12 | ): Promise { 13 | if (!guard(this)) { 14 | return undefined as never; 15 | } 16 | 17 | const reply = await this.send(commands); 18 | const lastReply = reply.at(-1); 19 | 20 | if (Array.isArray(lastReply)) { 21 | const [results] = lastReply; 22 | 23 | if (Array.isArray(results)) { 24 | return results; 25 | } 26 | 27 | return lastReply; 28 | } 29 | 30 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, 'PIPELINE'); 31 | } 32 | -------------------------------------------------------------------------------- /sources/command/bitfield.ro.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | import type { CommandBitfieldRoGetOperationOption } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | operations: CommandBitfieldRoGetOperationOption[], 8 | ) { 9 | const command = ['BITFIELD_RO', key]; 10 | 11 | for (const op of operations) { 12 | command.push('GET', op.type, `${op.offset}`); 13 | } 14 | 15 | return command; 16 | } 17 | 18 | export async function bitfieldRo( 19 | this: T, 20 | key: string, 21 | operations: CommandBitfieldRoGetOperationOption[], 22 | ): Promise { 23 | return await executeCommand( 24 | this, 25 | createCommand(key, operations), 26 | tryReplyToNumberArray, 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /sources/command/zinterstore.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildSortedSetInterCommand, 3 | executeCommand, 4 | tryReplyNumber, 5 | } from './utils/index.ts'; 6 | 7 | import type { CommandZInterOptions } from '../index.ts'; 8 | 9 | export function createCommand( 10 | destination: string, 11 | keys: string[], 12 | options: CommandZInterOptions, 13 | ) { 14 | return buildSortedSetInterCommand( 15 | ['ZINTERSTORE', destination], 16 | keys, 17 | options, 18 | ); 19 | } 20 | 21 | export async function zinterstore( 22 | this: T, 23 | destination: string, 24 | keys: string[], 25 | options: CommandZInterOptions = {}, 26 | ): Promise { 27 | return await executeCommand( 28 | this, 29 | createCommand(destination, keys, options), 30 | tryReplyNumber, 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /sources/command/client.list.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToString } from './utils/index.ts'; 2 | 3 | import type { CommandClientListOptions } from '../index.ts'; 4 | 5 | export function createCommand(options?: CommandClientListOptions) { 6 | const command = ['CLIENT', 'LIST']; 7 | 8 | if (options) { 9 | if (options.type) { 10 | command.push('TYPE', options.type); 11 | } 12 | if (options.identifiers && options.identifiers.length > 0) { 13 | command.push('ID', ...options.identifiers.map(String)); 14 | } 15 | } 16 | 17 | return command; 18 | } 19 | 20 | export async function clientList( 21 | this: T, 22 | options?: CommandClientListOptions, 23 | ): Promise { 24 | return await executeCommand(this, createCommand(options), tryReplyToString); 25 | } 26 | -------------------------------------------------------------------------------- /sources/command/lmove.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | import type { CommandLeftOrRightOption } from '../index.ts'; 4 | 5 | export function createCommand( 6 | source: string, 7 | destination: string, 8 | wherefrom: CommandLeftOrRightOption, 9 | whereto: CommandLeftOrRightOption, 10 | ) { 11 | return ['LMOVE', source, destination, wherefrom, whereto]; 12 | } 13 | 14 | export async function lmove( 15 | this: T, 16 | source: string, 17 | destination: string, 18 | wherefrom: CommandLeftOrRightOption, 19 | whereto: CommandLeftOrRightOption, 20 | ): Promise { 21 | return await executeCommand( 22 | this, 23 | createCommand(source, destination, wherefrom, whereto), 24 | tryReplyToStringOrNull, 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /sources/command/zunionstore.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildSortedSetInterCommand, 3 | executeCommand, 4 | tryReplyNumber, 5 | } from './utils/index.ts'; 6 | 7 | import type { CommandZInterOptions } from '../index.ts'; 8 | 9 | export function createCommand( 10 | destination: string, 11 | keys: string[], 12 | options: CommandZInterOptions = {}, 13 | ) { 14 | return buildSortedSetInterCommand( 15 | ['ZUNIONSTORE', destination], 16 | keys, 17 | options, 18 | ); 19 | } 20 | 21 | export async function zunionstore( 22 | this: T, 23 | destination: string, 24 | keys: string[], 25 | options: CommandZInterOptions = {}, 26 | ): Promise { 27 | return await executeCommand( 28 | this, 29 | createCommand(destination, keys, options), 30 | tryReplyNumber, 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /sources/command/xgroup.help.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | InvalidReplyPrefix, 4 | newCommandError, 5 | UnexpectedReplyPrefix, 6 | } from './utils/index.ts'; 7 | 8 | export function createCommand() { 9 | return ['XGROUP', 'HELP']; 10 | } 11 | 12 | export async function xgroupHelp(this: T): Promise { 13 | return await executeCommand(this, createCommand(), (reply, command) => { 14 | if (Array.isArray(reply)) { 15 | return reply.map((line) => { 16 | if (typeof line === 'string' || line instanceof Buffer) { 17 | return `${line}`; 18 | } 19 | 20 | throw newCommandError(`${InvalidReplyPrefix}: ${line}`, command); 21 | }); 22 | } 23 | 24 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 25 | }); 26 | } 27 | -------------------------------------------------------------------------------- /sources/command/function.help.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | InvalidReplyPrefix, 4 | newCommandError, 5 | UnexpectedReplyPrefix, 6 | } from './utils/index.ts'; 7 | 8 | export function createCommand() { 9 | return ['FUNCTION', 'HELP']; 10 | } 11 | 12 | export async function functionHelp(this: T): Promise { 13 | return await executeCommand(this, createCommand(), (reply, command) => { 14 | if (Array.isArray(reply)) { 15 | return reply.map((item) => { 16 | if (typeof item === 'string' || item instanceof Buffer) { 17 | return `${item}`; 18 | } 19 | 20 | throw newCommandError(`${InvalidReplyPrefix}: ${item}`, command); 21 | }); 22 | } 23 | 24 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 25 | }); 26 | } 27 | -------------------------------------------------------------------------------- /sources/command/geodist.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberOrNull } from './utils/index.ts'; 2 | 3 | import type { CommandGeoUnitOption } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | member1: string, 8 | member2: string, 9 | unit?: CommandGeoUnitOption, 10 | ) { 11 | const command = ['GEODIST', key, member1, member2]; 12 | 13 | if (unit) { 14 | command.push(unit); 15 | } 16 | 17 | return command; 18 | } 19 | 20 | export async function geodist( 21 | this: T, 22 | key: string, 23 | member1: string, 24 | member2: string, 25 | unit?: CommandGeoUnitOption, 26 | ): Promise { 27 | return await executeCommand( 28 | this, 29 | createCommand(key, member1, member2, unit), 30 | tryReplyToNumberOrNull, 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /sources/command/zrangebylex.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | import type { CommandLimitOptions } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | min: string, 8 | max: string, 9 | limit?: CommandLimitOptions, 10 | ) { 11 | const command = ['ZRANGEBYLEX', key, min, max]; 12 | 13 | if (limit) { 14 | command.push('LIMIT', `${limit.offset}`, `${limit.count}`); 15 | } 16 | 17 | return command; 18 | } 19 | 20 | export async function zrangebylex( 21 | this: T, 22 | key: string, 23 | min: string, 24 | max: string, 25 | limit?: CommandLimitOptions, 26 | ): Promise { 27 | return await executeCommand( 28 | this, 29 | createCommand(key, min, max, limit), 30 | tryReplyToStringArray, 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /sources/command/ts.add.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildTimeSeriesCommand, 3 | executeCommand, 4 | tryReplyNumber, 5 | } from './utils/index.ts'; 6 | 7 | import type { CommandTimeSeriesAddOptions } from '../index.ts'; 8 | 9 | export function createCommand( 10 | key: string, 11 | timestamp: number, 12 | value: number, 13 | options: CommandTimeSeriesAddOptions, 14 | ) { 15 | return buildTimeSeriesCommand( 16 | ['TS.ADD', key, `${timestamp}`, `${value}`], 17 | options, 18 | ); 19 | } 20 | 21 | export async function tsAdd( 22 | this: T, 23 | key: string, 24 | timestamp: number, 25 | value: number, 26 | options: CommandTimeSeriesAddOptions = {}, 27 | ): Promise { 28 | return await executeCommand( 29 | this, 30 | createCommand(key, timestamp, value, options), 31 | tryReplyNumber, 32 | ); 33 | } 34 | -------------------------------------------------------------------------------- /sources/command/srandmember.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | tryReplyToStringArray, 4 | tryReplyToStringOrNull, 5 | } from './utils/index.ts'; 6 | 7 | export function createCommand(key: string, count?: number) { 8 | const command = ['SRANDMEMBER', key]; 9 | 10 | if (count !== undefined) { 11 | command.push(`${count}`); 12 | } 13 | 14 | return command; 15 | } 16 | 17 | export async function srandmember( 18 | this: T, 19 | key: string, 20 | count?: number, 21 | ): Promise { 22 | return await executeCommand( 23 | this, 24 | createCommand(key, count), 25 | (reply, command) => { 26 | if (Array.isArray(reply)) { 27 | return tryReplyToStringArray(reply, command); 28 | } 29 | 30 | return tryReplyToStringOrNull(reply, command); 31 | }, 32 | ); 33 | } 34 | -------------------------------------------------------------------------------- /sources/command/command.list.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringArray } from './utils/index.ts'; 2 | 3 | import type { RespCommandListFilter } from '../index.ts'; 4 | 5 | export function createCommand(filter?: RespCommandListFilter) { 6 | const command = ['COMMAND', 'LIST']; 7 | 8 | if (filter?.module) { 9 | command.push('MODULE', filter.module); 10 | } 11 | 12 | if (filter?.aclcat) { 13 | command.push('ACLCAT', filter.aclcat); 14 | } 15 | 16 | if (filter?.pattern) { 17 | command.push('PATTERN', filter.pattern); 18 | } 19 | 20 | return command; 21 | } 22 | 23 | export async function commandList( 24 | this: T, 25 | filter?: RespCommandListFilter, 26 | ): Promise { 27 | return await executeCommand( 28 | this, 29 | createCommand(filter), 30 | tryReplyToStringArray, 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /sources/command/ts.info.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | newCommandError, 4 | processPairedArray, 5 | UnexpectedReplyPrefix, 6 | } from './utils/index.ts'; 7 | 8 | export function createCommand(key: string) { 9 | return ['TS.INFO', key]; 10 | } 11 | 12 | export async function tsInfo( 13 | this: T, 14 | key: string, 15 | ): Promise> { 16 | return await executeCommand(this, createCommand(key), (reply, command) => { 17 | if (!Array.isArray(reply)) { 18 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 19 | } 20 | 21 | const result: Record = {}; 22 | 23 | processPairedArray( 24 | reply, 25 | (key, value) => { 26 | result[key] = value; 27 | }, 28 | command, 29 | ); 30 | 31 | return result; 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /sources/command/xsetid.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | lastId: string, 6 | entriesAdded?: number, 7 | maxDeletedId?: string, 8 | ) { 9 | const command = ['XSETID', key, lastId]; 10 | 11 | if (entriesAdded !== undefined) { 12 | command.push('ENTRIESADDED', `${entriesAdded}`); 13 | } 14 | 15 | if (maxDeletedId !== undefined) { 16 | command.push('MAXDELETEDID', maxDeletedId); 17 | } 18 | 19 | return command; 20 | } 21 | 22 | export async function xsetid( 23 | this: T, 24 | key: string, 25 | lastId: string, 26 | entriesAdded?: number, 27 | maxDeletedId?: string, 28 | ) { 29 | return await executeCommand( 30 | this, 31 | createCommand(key, lastId, entriesAdded, maxDeletedId), 32 | tryReplyOK, 33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /sources/command/module.loadex.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | path: string, 5 | config?: Record, 6 | parameters?: string[], 7 | ) { 8 | const command = ['MODULE', 'LOADEX', path]; 9 | 10 | if (config) { 11 | for (const [name, value] of Object.entries(config)) { 12 | command.push('CONFIG', name, value); 13 | } 14 | } 15 | 16 | if (parameters?.length) { 17 | command.push('ARGS', ...parameters); 18 | } 19 | 20 | return command; 21 | } 22 | 23 | export async function moduleLoadex( 24 | this: T, 25 | path: string, 26 | config?: Record, 27 | parameters?: string[], 28 | ) { 29 | return await executeCommand( 30 | this, 31 | createCommand(path, config, parameters), 32 | tryReplyOK, 33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /sources/command/ts.queryindex.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | newCommandError, 4 | tryReplyToStringArray, 5 | UnexpectedReplyPrefix, 6 | } from './utils/index.ts'; 7 | 8 | export function createCommand(filter: Record) { 9 | const command = ['TS.QUERYINDEX']; 10 | 11 | for (const [label, value] of Object.entries(filter)) { 12 | command.push(label, '=', value); 13 | } 14 | 15 | return command; 16 | } 17 | 18 | export async function tsQueryindex( 19 | this: T, 20 | filter: Record, 21 | ): Promise { 22 | return await executeCommand(this, createCommand(filter), (reply, command) => { 23 | if (!Array.isArray(reply)) { 24 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 25 | } 26 | 27 | return tryReplyToStringArray(reply, command); 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /sources/command/function.restore.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { CommandFunctionRestoreOptions } from '../index.ts'; 4 | 5 | export function createCommand( 6 | dump: string, 7 | options?: CommandFunctionRestoreOptions, 8 | ) { 9 | const command = ['FUNCTION', 'RESTORE']; 10 | 11 | if (options?.replace) { 12 | command.push('REPLACE'); 13 | } 14 | 15 | if (options?.flush) { 16 | command.push('FLUSH'); 17 | } 18 | 19 | if (options?.append) { 20 | command.push('APPEND'); 21 | } 22 | 23 | command.push(dump); 24 | 25 | return command; 26 | } 27 | 28 | export async function functionRestore( 29 | this: T, 30 | dump: string, 31 | options?: CommandFunctionRestoreOptions, 32 | ) { 33 | return await executeCommand(this, createCommand(dump, options), tryReplyOK); 34 | } 35 | -------------------------------------------------------------------------------- /sources/command/xrevrange.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | newCommandError, 4 | tryReplyToStreamEntry, 5 | UnexpectedReplyPrefix, 6 | } from './utils/index.ts'; 7 | 8 | import type { RespStreamEntry } from '../index.ts'; 9 | 10 | export function createCommand(key: string, end: string, start: string) { 11 | return ['XREVRANGE', key, end, start]; 12 | } 13 | 14 | export async function xrevrange( 15 | this: T, 16 | key: string, 17 | end: string, 18 | start: string, 19 | ): Promise { 20 | return await executeCommand( 21 | this, 22 | createCommand(key, end, start), 23 | (reply, command) => { 24 | if (!Array.isArray(reply)) { 25 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 26 | } 27 | 28 | return reply.map(tryReplyToStreamEntry); 29 | }, 30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /sources/command/client.unblock.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { CommandClientUnblockOptions } from '../index.ts'; 4 | 5 | export function createCommand( 6 | clientId: number, 7 | options?: CommandClientUnblockOptions, 8 | ) { 9 | const command = ['CLIENT', 'UNBLOCK', `${clientId}`]; 10 | 11 | if (options) { 12 | if (options.timeout) { 13 | command.push('TIMEOUT'); 14 | } 15 | 16 | if (options.error) { 17 | command.push('ERROR'); 18 | } 19 | } 20 | 21 | return command; 22 | } 23 | 24 | export async function clientUnblock( 25 | this: T, 26 | clientId: number, 27 | options?: CommandClientUnblockOptions, 28 | ): Promise { 29 | return await executeCommand( 30 | this, 31 | createCommand(clientId, options), 32 | tryReplyNumber, 33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /sources/command/zintercard.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildSortedSetInterCommand, 3 | executeCommand, 4 | tryReplyNumber, 5 | } from './utils/index.ts'; 6 | 7 | import type { CommandZInterOptions } from '../index.ts'; 8 | 9 | export function createCommand( 10 | keys: string[], 11 | limit: number | undefined, 12 | options: CommandZInterOptions, 13 | ) { 14 | const command = buildSortedSetInterCommand(['ZINTERCARD'], keys, options); 15 | 16 | if (limit !== undefined) { 17 | command.push('LIMIT', `${limit}`); 18 | } 19 | 20 | return command; 21 | } 22 | 23 | export async function zintercard( 24 | this: T, 25 | keys: string[], 26 | limit?: number, 27 | options: CommandZInterOptions = {}, 28 | ): Promise { 29 | return await executeCommand( 30 | this, 31 | createCommand(keys, limit, options), 32 | tryReplyNumber, 33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /sources/command/blmove.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | import type { CommandLeftOrRightOption } from '../index.ts'; 4 | 5 | export function createCommand( 6 | source: string, 7 | destination: string, 8 | whereFrom: CommandLeftOrRightOption, 9 | whereTo: CommandLeftOrRightOption, 10 | timeout: number, 11 | ) { 12 | return ['BLMOVE', source, destination, whereFrom, whereTo, `${timeout}`]; 13 | } 14 | 15 | export async function blmove( 16 | this: T, 17 | source: string, 18 | destination: string, 19 | whereFrom: CommandLeftOrRightOption, 20 | whereTo: CommandLeftOrRightOption, 21 | timeout: number, 22 | ): Promise { 23 | return await executeCommand( 24 | this, 25 | createCommand(source, destination, whereFrom, whereTo, timeout), 26 | tryReplyToStringOrNull, 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /sources/command/hmset.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { StringOrBuffer } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | mapping: Record, 8 | ) { 9 | const command: StringOrBuffer[] = ['HMSET', key]; 10 | 11 | for (const [field, value] of Object.entries(mapping)) { 12 | command.push(field, value); 13 | } 14 | 15 | return command; 16 | } 17 | 18 | /** 19 | * @deprecated 20 | * @see https://redis.io/docs/latest/commands/hmset/ 21 | * As of Redis version 4.0.0, this command is regarded as deprecated. 22 | * Use `hset` instead. 23 | */ 24 | export async function hmset( 25 | this: T, 26 | key: string, 27 | mapping: Record, 28 | ) { 29 | return await executeCommand(this, createCommand(key, mapping), tryReplyOK); 30 | } 31 | -------------------------------------------------------------------------------- /sources/command/shutdown.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { CommandShutdownOptions } from '../index.ts'; 4 | 5 | export function createCommand(options?: CommandShutdownOptions) { 6 | const command = ['SHUTDOWN']; 7 | 8 | if (options) { 9 | if (options.nosave) { 10 | command.push('NOSAVE'); 11 | } else if (options.save) { 12 | command.push('SAVE'); 13 | } 14 | 15 | if (options.now) { 16 | command.push('NOW'); 17 | } 18 | 19 | if (options.force) { 20 | command.push('FORCE'); 21 | } 22 | 23 | if (options.abort) { 24 | command.push('ABORT'); 25 | } 26 | } 27 | 28 | return command; 29 | } 30 | 31 | export async function shutdown(this: T, options?: CommandShutdownOptions) { 32 | return await executeCommand(this, createCommand(options), tryReplyOK); 33 | } 34 | -------------------------------------------------------------------------------- /sources/command/xgroup.create.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | groupname: string, 6 | id: string, 7 | mkstream?: boolean, 8 | entriesRead?: number, 9 | ) { 10 | const command = ['XGROUP', 'CREATE', key, groupname, id]; 11 | 12 | if (mkstream) { 13 | command.push('MKSTREAM'); 14 | } 15 | 16 | if (entriesRead !== undefined) { 17 | command.push('ENTRIESREAD', `${entriesRead}`); 18 | } 19 | 20 | return command; 21 | } 22 | 23 | export async function xgroupCreate( 24 | this: T, 25 | key: string, 26 | groupname: string, 27 | id: string, 28 | mkstream?: boolean, 29 | entriesRead?: number, 30 | ) { 31 | return await executeCommand( 32 | this, 33 | createCommand(key, groupname, id, mkstream, entriesRead), 34 | tryReplyOK, 35 | ); 36 | } 37 | -------------------------------------------------------------------------------- /sources/command/bitcount.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { CommandStartToEndAndBitOrByteOptions } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | options?: CommandStartToEndAndBitOrByteOptions, 8 | ) { 9 | const command = ['BITCOUNT', key]; 10 | 11 | if (options?.start !== undefined && options?.end !== undefined) { 12 | command.push(`${options.start}`, `${options.end}`); 13 | 14 | if (options.mode) { 15 | command.push(options.mode); 16 | } 17 | } 18 | 19 | return command; 20 | } 21 | 22 | export async function bitcount( 23 | this: T, 24 | key: string, 25 | options?: CommandStartToEndAndBitOrByteOptions, 26 | ): Promise { 27 | return await executeCommand( 28 | this, 29 | createCommand(key, options), 30 | tryReplyNumber, 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /sources/command/copy.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { CommandCopyOptions } from '../index.ts'; 4 | 5 | export function createCommand( 6 | source: string, 7 | destination: string, 8 | options?: CommandCopyOptions, 9 | ) { 10 | const command = ['COPY', source, destination]; 11 | 12 | if (options?.destinationDatabase !== undefined) { 13 | command.push('DB', `${options.destinationDatabase}`); 14 | } 15 | 16 | if (options?.replace) { 17 | command.push('REPLACE'); 18 | } 19 | 20 | return command; 21 | } 22 | 23 | export async function copy( 24 | this: T, 25 | source: string, 26 | destination: string, 27 | options?: CommandCopyOptions, 28 | ): Promise { 29 | return await executeCommand( 30 | this, 31 | createCommand(source, destination, options), 32 | tryReplyNumber, 33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /sources/command/bf.reserve.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | errorRate: number, 6 | capacity: number, 7 | expansion?: number, 8 | nonScaling?: boolean, 9 | ) { 10 | const command = ['BF.RESERVE', key, `${errorRate}`, `${capacity}`]; 11 | 12 | if (expansion !== undefined) { 13 | command.push('EXPANSION', `${expansion}`); 14 | } 15 | 16 | if (nonScaling) { 17 | command.push('NONSCALING'); 18 | } 19 | 20 | return command; 21 | } 22 | 23 | export async function bfReserve( 24 | this: T, 25 | key: string, 26 | errorRate: number, 27 | capacity: number, 28 | expansion?: number, 29 | nonScaling?: boolean, 30 | ) { 31 | return await executeCommand( 32 | this, 33 | createCommand(key, errorRate, capacity, expansion, nonScaling), 34 | tryReplyOK, 35 | ); 36 | } 37 | -------------------------------------------------------------------------------- /sources/command/zrangestore.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildSortedSetRangeStoreCommand, 3 | executeCommand, 4 | tryReplyNumber, 5 | } from './utils/index.ts'; 6 | 7 | import type { CommandZRangeStoreOptions } from '../index.ts'; 8 | 9 | export function createCommand( 10 | destination: string, 11 | source: string, 12 | min: string, 13 | max: string, 14 | options: CommandZRangeStoreOptions, 15 | ) { 16 | return buildSortedSetRangeStoreCommand( 17 | ['ZRANGESTORE', destination, source, min, max], 18 | options, 19 | ); 20 | } 21 | 22 | export async function zrangestore( 23 | this: T, 24 | destination: string, 25 | source: string, 26 | min: string, 27 | max: string, 28 | options: CommandZRangeStoreOptions = {}, 29 | ): Promise { 30 | return await executeCommand( 31 | this, 32 | createCommand(destination, source, min, max, options), 33 | tryReplyNumber, 34 | ); 35 | } 36 | -------------------------------------------------------------------------------- /sources/command/scan.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildScanCommand, 3 | executeCommand, 4 | tryReplyToScan, 5 | tryReplyToStringArray, 6 | } from './utils/index.ts'; 7 | 8 | import type { CommandScanOptions } from '../index.ts'; 9 | 10 | export function createCommand(cursor: string, options: CommandScanOptions) { 11 | return buildScanCommand(['SCAN'], cursor, options); 12 | } 13 | 14 | export async function* scan( 15 | this: T, 16 | options: CommandScanOptions = {}, 17 | ): AsyncGenerator { 18 | let cursor = '0'; 19 | const { count = 10, match, type } = options; 20 | 21 | do { 22 | const command = createCommand(cursor, { count, match, type }); 23 | 24 | const reply = await executeCommand(this, command); 25 | 26 | const [newCursor, elements] = tryReplyToScan(reply); 27 | cursor = newCursor; 28 | 29 | yield tryReplyToStringArray(elements, command); 30 | } while (cursor !== '0'); 31 | } 32 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowImportingTsExtensions": true, 4 | "allowSyntheticDefaultImports": true, 5 | "baseUrl": "./", 6 | "declaration": true, 7 | "emitDeclarationOnly": true, 8 | "emitDecoratorMetadata": true, 9 | "esModuleInterop": true, 10 | "experimentalDecorators": true, 11 | "incremental": true, 12 | "lib": ["ESNext"], 13 | "module": "NodeNext", 14 | "moduleResolution": "NodeNext", 15 | "noUnusedLocals": true, 16 | "noUnusedParameters": true, 17 | "noImplicitReturns": true, 18 | "noImplicitAny": true, 19 | "outDir": "./distributions", 20 | "rootDirs": ["sources"], 21 | "strict": true, 22 | "sourceMap": true, 23 | "strictNullChecks": true, 24 | "skipLibCheck": true, 25 | "target": "ESNext", 26 | "types": ["node"], 27 | "verbatimModuleSyntax": true 28 | }, 29 | "include": ["./sources/**/*.ts"] 30 | } 31 | -------------------------------------------------------------------------------- /sources/command/type.ts: -------------------------------------------------------------------------------- 1 | import { RespDataTypes } from '../index.ts'; 2 | import { 3 | executeCommand, 4 | newCommandError, 5 | UnexpectedReplyPrefix, 6 | } from './utils/index.ts'; 7 | 8 | export function createCommand(key: string) { 9 | return ['TYPE', key]; 10 | } 11 | 12 | export async function type( 13 | this: T, 14 | key: string, 15 | ): Promise { 16 | return await executeCommand(this, createCommand(key), (reply, command) => { 17 | if (typeof reply === 'string' || reply instanceof Buffer) { 18 | const typeString = `${reply}`.toUpperCase(); 19 | 20 | if (Object.values(RespDataTypes).includes(typeString as RespDataTypes)) { 21 | return typeString as RespDataTypes; 22 | } 23 | 24 | if (typeString === 'NONE') { 25 | return 'NONE'; 26 | } 27 | } 28 | 29 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 30 | }); 31 | } 32 | -------------------------------------------------------------------------------- /sources/command/pubsub.numsub.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | processPairedArray, 4 | tryReplyNumber, 5 | } from './utils/index.ts'; 6 | 7 | import type { RespPubsubNumsub } from '../index.ts'; 8 | 9 | export function createCommand(channels?: string[]) { 10 | const command = ['PUBSUB', 'NUMSUB']; 11 | 12 | if (channels?.length) { 13 | command.push(...channels); 14 | } 15 | 16 | return command; 17 | } 18 | 19 | export async function pubsubNumsub( 20 | this: T, 21 | channels?: string[], 22 | ): Promise { 23 | return await executeCommand( 24 | this, 25 | createCommand(channels), 26 | (reply, command) => { 27 | const result: RespPubsubNumsub = {}; 28 | 29 | processPairedArray( 30 | reply, 31 | (channel, count) => { 32 | result[channel] = tryReplyNumber(count, command); 33 | }, 34 | 'PUBSUB_NUMSUB', 35 | ); 36 | 37 | return result; 38 | }, 39 | ); 40 | } 41 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | paths: 7 | - ".github/workflows/build.yaml" 8 | - "sources/**" 9 | - "scripts/**" 10 | pull_request: 11 | branches: [main] 12 | paths: 13 | - ".github/workflows/build.yaml" 14 | - "sources/**" 15 | - "scripts/**" 16 | 17 | jobs: 18 | build: 19 | name: Build 20 | runs-on: ubuntu-latest 21 | steps: 22 | - name: Checkout Repository 23 | uses: actions/checkout@v4 24 | 25 | - name: Setup Node.js 26 | uses: actions/setup-node@v4 27 | with: 28 | node-version: "22.x" 29 | cache: "npm" 30 | registry-url: "https://registry.npmjs.org" 31 | 32 | - name: Install Dependencies 33 | run: npm ci 34 | 35 | - name: Lint 36 | run: npm run lint 37 | 38 | - name: Format 39 | run: npm run format 40 | 41 | - name: Build 42 | run: npm run build 43 | -------------------------------------------------------------------------------- /sources/command/sscan.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildScanCommand, 3 | executeCommand, 4 | tryReplyToScan, 5 | tryReplyToStringArray, 6 | } from './utils/index.ts'; 7 | 8 | import type { CommandScanBaseOptions } from '../index.ts'; 9 | 10 | export function createCommand( 11 | key: string, 12 | cursor: string, 13 | options: CommandScanBaseOptions, 14 | ) { 15 | return buildScanCommand(['SSCAN', key], cursor, options); 16 | } 17 | 18 | export async function* sscan( 19 | this: T, 20 | key: string, 21 | options: CommandScanBaseOptions = {}, 22 | ): AsyncGenerator { 23 | let cursor = '0'; 24 | const { count = 10, match } = options; 25 | 26 | do { 27 | const command = createCommand(key, cursor, { count, match }); 28 | 29 | const reply = await executeCommand(this, command); 30 | 31 | const [newCursor, elements] = tryReplyToScan(reply); 32 | cursor = newCursor; 33 | 34 | yield tryReplyToStringArray(elements, command); 35 | } while (cursor !== '0'); 36 | } 37 | -------------------------------------------------------------------------------- /sources/command/bf.scandump.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | InvalidReplyPrefix, 4 | newCommandError, 5 | UnexpectedReplyPrefix, 6 | } from './utils/index.ts'; 7 | 8 | export function createCommand(key: string, iterator: number) { 9 | return ['BF.SCANDUMP', key, `${iterator}`]; 10 | } 11 | 12 | export async function bfScandump( 13 | this: T, 14 | key: string, 15 | iterator: number, 16 | ): Promise<[nextIterator: number, data: Buffer]> { 17 | return await executeCommand( 18 | this, 19 | createCommand(key, iterator), 20 | (reply, command) => { 21 | if (Array.isArray(reply) && reply.length === 2) { 22 | const [nextIterator, data] = reply; 23 | 24 | if (!(data instanceof Buffer)) { 25 | throw newCommandError(`${InvalidReplyPrefix}: ${data}`, command); 26 | } 27 | 28 | return [Number(nextIterator), data]; 29 | } 30 | 31 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 32 | }, 33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /sources/command/json.arrindex.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToNumberArray } from './utils/index.ts'; 2 | 3 | import type { CommandJsonArrIndexOptions } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | path: string, 8 | value: string, 9 | options?: CommandJsonArrIndexOptions, 10 | ) { 11 | const command = ['JSON.ARRINDEX', key, path, value]; 12 | 13 | if (options?.start !== undefined) { 14 | command.push(`${options.start}`); 15 | 16 | if (options.stop !== undefined) { 17 | command.push(`${options.stop}`); 18 | } 19 | } 20 | 21 | return command; 22 | } 23 | 24 | export async function jsonArrindex( 25 | this: T, 26 | key: string, 27 | path: string, 28 | value: string, 29 | options?: CommandJsonArrIndexOptions, 30 | ): Promise<(number | null)[]> { 31 | return await executeCommand( 32 | this, 33 | createCommand(key, path, value, options), 34 | (reply, command) => tryReplyToNumberArray(reply, command, true), 35 | ); 36 | } 37 | -------------------------------------------------------------------------------- /sources/command/bitpos.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { 4 | CommandStartToEndAndBitOrByteOptions, 5 | RespBit, 6 | } from '../index.ts'; 7 | 8 | export function createCommand( 9 | key: string, 10 | bit: RespBit, 11 | options?: CommandStartToEndAndBitOrByteOptions, 12 | ) { 13 | const command = ['BITPOS', key, `${bit}`]; 14 | 15 | if (options?.start !== undefined) { 16 | command.push(`${options.start}`); 17 | 18 | if (options.end !== undefined) { 19 | command.push(`${options.end}`); 20 | 21 | if (options.mode) { 22 | command.push(options.mode); 23 | } 24 | } 25 | } 26 | 27 | return command; 28 | } 29 | 30 | export async function bitpos( 31 | this: T, 32 | key: string, 33 | bit: RespBit, 34 | options?: CommandStartToEndAndBitOrByteOptions, 35 | ): Promise { 36 | return await executeCommand( 37 | this, 38 | createCommand(key, bit, options), 39 | tryReplyNumber, 40 | ); 41 | } 42 | -------------------------------------------------------------------------------- /website/public/globe.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sources/command/ts.createrule.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { CommandTimeSeriesCreateRuleOptions } from '../index.ts'; 4 | 5 | export function createCommand( 6 | sourceKey: string, 7 | destinationKey: string, 8 | options: CommandTimeSeriesCreateRuleOptions, 9 | ) { 10 | const command = [ 11 | 'TS.CREATERULE', 12 | sourceKey, 13 | destinationKey, 14 | 'AGGREGATION', 15 | options.aggregation.type, 16 | `${options.aggregation.bucketDuration}`, 17 | ]; 18 | 19 | if (options.aggregation.alignTimestamp !== undefined) { 20 | command.push(`${options.aggregation.alignTimestamp}`); 21 | } 22 | 23 | return command; 24 | } 25 | 26 | export async function tsCreaterule( 27 | this: T, 28 | sourceKey: string, 29 | destinationKey: string, 30 | options: CommandTimeSeriesCreateRuleOptions, 31 | ) { 32 | return await executeCommand( 33 | this, 34 | createCommand(sourceKey, destinationKey, options), 35 | tryReplyOK, 36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /sources/command/cf.reserve.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | export function createCommand( 4 | key: string, 5 | capacity: number, 6 | bucketSize?: number, 7 | maxIterations?: number, 8 | expansion?: number, 9 | ) { 10 | const command = ['CF.RESERVE', key, `${capacity}`]; 11 | 12 | if (bucketSize !== undefined) { 13 | command.push('BUCKETSIZE', `${bucketSize}`); 14 | } 15 | 16 | if (maxIterations !== undefined) { 17 | command.push('MAXITERATIONS', `${maxIterations}`); 18 | } 19 | 20 | if (expansion !== undefined) { 21 | command.push('EXPANSION', `${expansion}`); 22 | } 23 | 24 | return command; 25 | } 26 | 27 | export async function cfReserve( 28 | this: T, 29 | key: string, 30 | capacity: number, 31 | bucketSize?: number, 32 | maxIterations?: number, 33 | expansion?: number, 34 | ) { 35 | return await executeCommand( 36 | this, 37 | createCommand(key, capacity, bucketSize, maxIterations, expansion), 38 | tryReplyOK, 39 | ); 40 | } 41 | -------------------------------------------------------------------------------- /sources/command/pubsub.shardnumsub.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | processPairedArray, 4 | tryReplyNumber, 5 | } from './utils/index.ts'; 6 | 7 | import type { RespPubsubShardNumsub } from '../index.ts'; 8 | 9 | export function createCommand(shardChannels?: string[]) { 10 | const command = ['PUBSUB', 'SHARDNUMSUB']; 11 | 12 | if (shardChannels?.length) { 13 | command.push(...shardChannels); 14 | } 15 | 16 | return command; 17 | } 18 | 19 | export async function pubsubShardnumsub( 20 | this: T, 21 | shardChannels?: string[], 22 | ): Promise { 23 | return await executeCommand( 24 | this, 25 | createCommand(shardChannels), 26 | (reply, command) => { 27 | const result: RespPubsubShardNumsub = {}; 28 | 29 | processPairedArray( 30 | reply, 31 | (channel, count) => { 32 | result[channel] = tryReplyNumber(count, command); 33 | }, 34 | 'PUBSUB_SHARDNUMSUB', 35 | ); 36 | 37 | return result; 38 | }, 39 | ); 40 | } 41 | -------------------------------------------------------------------------------- /sources/command/geohash.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | InvalidReplyPrefix, 4 | newCommandError, 5 | UnexpectedReplyPrefix, 6 | } from './utils/index.ts'; 7 | 8 | export function createCommand(key: string, members: string[]) { 9 | return ['GEOHASH', key, ...members]; 10 | } 11 | 12 | export async function geohash( 13 | this: T, 14 | key: string, 15 | members: string[], 16 | ): Promise> { 17 | return await executeCommand( 18 | this, 19 | createCommand(key, members), 20 | (reply, command) => { 21 | if (!Array.isArray(reply)) { 22 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 23 | } 24 | 25 | return reply.map((hash) => { 26 | if (hash === null) { 27 | return null; 28 | } 29 | 30 | if (typeof hash === 'string' || hash instanceof Buffer) { 31 | return `${hash}`; 32 | } 33 | 34 | throw newCommandError(`${InvalidReplyPrefix}: ${hash}`, command); 35 | }); 36 | }, 37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /sources/command/json.set.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { CommandJsonSetOptions, RespOK } from '../index.ts'; 4 | 5 | export function createCommand( 6 | key: string, 7 | path: string, 8 | value: string, 9 | options?: CommandJsonSetOptions, 10 | ) { 11 | const command = ['JSON.SET', key, path, value]; 12 | 13 | if (options) { 14 | if (options.nx) { 15 | command.push('NX'); 16 | } 17 | 18 | if (options.xx) { 19 | command.push('XX'); 20 | } 21 | } 22 | 23 | return command; 24 | } 25 | 26 | export async function jsonSet( 27 | this: T, 28 | key: string, 29 | path: string, 30 | value: string, 31 | options?: CommandJsonSetOptions, 32 | ): Promise { 33 | return await executeCommand( 34 | this, 35 | createCommand(key, path, value, options), 36 | (reply, command) => { 37 | if (reply === null) { 38 | return null; 39 | } 40 | 41 | return tryReplyOK(reply, command); 42 | }, 43 | ); 44 | } 45 | -------------------------------------------------------------------------------- /sources/command/cf.insert.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildCuckooFilterInsertCommand, 3 | executeCommand, 4 | newCommandError, 5 | tryReplyToBoolean, 6 | UnexpectedReplyPrefix, 7 | } from './utils/index.ts'; 8 | 9 | import type { CommandCuckooFilterInsertOptions } from '../index.ts'; 10 | 11 | export function createCommand( 12 | key: string, 13 | items: string[], 14 | options?: CommandCuckooFilterInsertOptions, 15 | ) { 16 | return buildCuckooFilterInsertCommand('CF.INSERT', key, items, options); 17 | } 18 | 19 | export async function cfInsert( 20 | this: T, 21 | key: string, 22 | items: string[], 23 | options?: CommandCuckooFilterInsertOptions, 24 | ): Promise { 25 | return await executeCommand( 26 | this, 27 | createCommand(key, items, options), 28 | (reply, command) => { 29 | if (Array.isArray(reply)) { 30 | return reply.map((value) => tryReplyToBoolean(value, command)); 31 | } 32 | 33 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 34 | }, 35 | ); 36 | } 37 | -------------------------------------------------------------------------------- /sources/command/cf.insertnx.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildCuckooFilterInsertCommand, 3 | executeCommand, 4 | newCommandError, 5 | tryReplyToBoolean, 6 | UnexpectedReplyPrefix, 7 | } from './utils/index.ts'; 8 | 9 | import type { CommandCuckooFilterInsertOptions } from '../index.ts'; 10 | 11 | export function createCommand( 12 | key: string, 13 | items: string[], 14 | options?: CommandCuckooFilterInsertOptions, 15 | ) { 16 | return buildCuckooFilterInsertCommand('CF.INSERTNX', key, items, options); 17 | } 18 | 19 | export async function cfInsertnx( 20 | this: T, 21 | key: string, 22 | items: string[], 23 | options?: CommandCuckooFilterInsertOptions, 24 | ): Promise { 25 | return await executeCommand( 26 | this, 27 | createCommand(key, items, options), 28 | (reply, command) => { 29 | if (Array.isArray(reply)) { 30 | return reply.map((value) => tryReplyToBoolean(value, command)); 31 | } 32 | 33 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 34 | }, 35 | ); 36 | } 37 | -------------------------------------------------------------------------------- /sources/command/blpop.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | newCommandError, 4 | UnexpectedReplyPrefix, 5 | } from './utils/index.ts'; 6 | 7 | export function createCommand(keys: string[], timeout: number) { 8 | return ['BLPOP', ...keys, `${timeout}`]; 9 | } 10 | 11 | export async function blpop( 12 | this: T, 13 | keys: string[], 14 | timeout: number, 15 | ): Promise<[string, string] | null> { 16 | return await executeCommand( 17 | this, 18 | createCommand(keys, timeout), 19 | (reply, command) => { 20 | if (reply === null) { 21 | return null; 22 | } 23 | 24 | if (Array.isArray(reply) && reply.length === 2) { 25 | const [key, value] = reply; 26 | 27 | if ( 28 | (typeof key === 'string' || key instanceof Buffer) && 29 | (typeof value === 'string' || value instanceof Buffer) 30 | ) { 31 | return [`${key}`, `${value}`]; 32 | } 33 | } 34 | 35 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 36 | }, 37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /sources/command/brpop.ts: -------------------------------------------------------------------------------- 1 | import { 2 | executeCommand, 3 | newCommandError, 4 | UnexpectedReplyPrefix, 5 | } from './utils/index.ts'; 6 | 7 | export function createCommand(keys: string[], timeout: number) { 8 | return ['BRPOP', ...keys, `${timeout}`]; 9 | } 10 | 11 | export async function brpop( 12 | this: T, 13 | keys: string[], 14 | timeout: number, 15 | ): Promise<[string, string] | null> { 16 | return await executeCommand( 17 | this, 18 | createCommand(keys, timeout), 19 | (reply, command) => { 20 | if (reply === null) { 21 | return null; 22 | } 23 | 24 | if (Array.isArray(reply) && reply.length === 2) { 25 | const [key, value] = reply; 26 | 27 | if ( 28 | (typeof key === 'string' || key instanceof Buffer) && 29 | (typeof value === 'string' || value instanceof Buffer) 30 | ) { 31 | return [`${key}`, `${value}`]; 32 | } 33 | } 34 | 35 | throw newCommandError(`${UnexpectedReplyPrefix}: ${reply}`, command); 36 | }, 37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /sources/command/failover.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyOK } from './utils/index.ts'; 2 | 3 | import type { CommandFailoverOptions } from '../index.ts'; 4 | 5 | export function createCommand(options?: CommandFailoverOptions) { 6 | const command = ['FAILOVER']; 7 | 8 | if (options?.to) { 9 | command.push('TO', options.to.host, `${options.to.port}`); 10 | 11 | if (options.to.username && options.to.password) { 12 | command.push(options.to.username, options.to.password); 13 | } else if (options.to.password) { 14 | command.push(options.to.password); 15 | } 16 | } 17 | 18 | if (options?.force) { 19 | command.push('FORCE'); 20 | } 21 | 22 | if (options?.abort) { 23 | command.push('ABORT'); 24 | } 25 | 26 | if (options?.timeout !== undefined) { 27 | command.push('TIMEOUT', `${options.timeout}`); 28 | } 29 | 30 | return command; 31 | } 32 | 33 | export async function failover(this: T, options?: CommandFailoverOptions) { 34 | return await executeCommand(this, createCommand(options), tryReplyOK); 35 | } 36 | -------------------------------------------------------------------------------- /sources/command/json.get.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyToStringOrNull } from './utils/index.ts'; 2 | 3 | import type { CommandJsonGetOptions } from '../index.ts'; 4 | 5 | export function createCommand(key: string, options?: CommandJsonGetOptions) { 6 | const command = ['JSON.GET', key]; 7 | 8 | if (options) { 9 | if (options.indent !== undefined) { 10 | command.push('INDENT', options.indent); 11 | } 12 | 13 | if (options.newline !== undefined) { 14 | command.push('NEWLINE', options.newline); 15 | } 16 | 17 | if (options.space !== undefined) { 18 | command.push('SPACE', options.space); 19 | } 20 | 21 | if (options.path?.length) { 22 | command.push(...options.path); 23 | } 24 | } 25 | 26 | return command; 27 | } 28 | 29 | export async function jsonGet( 30 | this: T, 31 | key: string, 32 | options?: CommandJsonGetOptions, 33 | ): Promise { 34 | return await executeCommand( 35 | this, 36 | createCommand(key, options), 37 | tryReplyToStringOrNull, 38 | ); 39 | } 40 | -------------------------------------------------------------------------------- /sources/command/geosearchstore.ts: -------------------------------------------------------------------------------- 1 | import { 2 | buildGeoSearchCommand, 3 | executeCommand, 4 | tryReplyNumber, 5 | } from './utils/index.ts'; 6 | 7 | import type { 8 | CommandGeoSearchByOptions, 9 | CommandGeoSearchFromOptions, 10 | CommandGeoSearchStoreOptions, 11 | } from '../index.ts'; 12 | 13 | export function createCommand( 14 | destination: string, 15 | source: string, 16 | from: CommandGeoSearchFromOptions, 17 | by: CommandGeoSearchByOptions, 18 | options?: CommandGeoSearchStoreOptions, 19 | ) { 20 | return buildGeoSearchCommand( 21 | ['GEOSEARCHSTORE', destination, source], 22 | from, 23 | by, 24 | options, 25 | ); 26 | } 27 | 28 | export async function geosearchstore( 29 | this: T, 30 | destination: string, 31 | source: string, 32 | from: CommandGeoSearchFromOptions, 33 | by: CommandGeoSearchByOptions, 34 | options?: CommandGeoSearchStoreOptions, 35 | ): Promise { 36 | return await executeCommand( 37 | this, 38 | createCommand(destination, source, from, by, options), 39 | tryReplyNumber, 40 | ); 41 | } 42 | -------------------------------------------------------------------------------- /sources/command/geoadd.ts: -------------------------------------------------------------------------------- 1 | import { executeCommand, tryReplyNumber } from './utils/index.ts'; 2 | 3 | import type { 4 | CommandGeoAddMemberOption, 5 | CommandGeoAddOptions, 6 | } from '../index.ts'; 7 | 8 | export function createCommand( 9 | key: string, 10 | members: CommandGeoAddMemberOption[], 11 | options?: CommandGeoAddOptions, 12 | ) { 13 | const command = ['GEOADD', key]; 14 | 15 | if (options?.nx) { 16 | command.push('NX'); 17 | } 18 | 19 | if (options?.xx) { 20 | command.push('XX'); 21 | } 22 | 23 | if (options?.ch) { 24 | command.push('CH'); 25 | } 26 | 27 | for (const { longitude, latitude, member } of members) { 28 | command.push(`${longitude}`, `${latitude}`, `${member}`); 29 | } 30 | 31 | return command; 32 | } 33 | 34 | export async function geoadd( 35 | this: T, 36 | key: string, 37 | members: CommandGeoAddMemberOption[], 38 | options?: CommandGeoAddOptions, 39 | ): Promise { 40 | return await executeCommand( 41 | this, 42 | createCommand(key, members, options), 43 | tryReplyNumber, 44 | ); 45 | } 46 | --------------------------------------------------------------------------------