From b6f2ed32e57c698e6b60aeddcfbaa976f324da07 Mon Sep 17 00:00:00 2001 From: Mehmet Dogan Date: Wed, 12 Aug 2026 19:57:37 +0300 Subject: [PATCH 01/12] Add Redis commands reference pages --- docs.json | 391 + llms-full.txt | 45801 +++++++++++++++- llms.txt | 294 +- redis/commands/bitmap/bitcount.mdx | 165 + redis/commands/bitmap/bitfield-ro.mdx | 161 + redis/commands/bitmap/bitfield.mdx | 165 + redis/commands/bitmap/bitop.mdx | 176 + redis/commands/bitmap/bitpos.mdx | 167 + redis/commands/bitmap/getbit.mdx | 165 + redis/commands/bitmap/overview.mdx | 16 + redis/commands/bitmap/setbit.mdx | 166 + redis/commands/connection/auth.mdx | 145 + redis/commands/connection/client-getname.mdx | 143 + redis/commands/connection/client-id.mdx | 143 + redis/commands/connection/client-info.mdx | 143 + redis/commands/connection/client-list.mdx | 143 + redis/commands/connection/client-setinfo.mdx | 148 + redis/commands/connection/client-setname.mdx | 146 + redis/commands/connection/echo.mdx | 165 + redis/commands/connection/hello.mdx | 146 + redis/commands/connection/overview.mdx | 22 + redis/commands/connection/ping.mdx | 170 + redis/commands/connection/quit.mdx | 144 + redis/commands/connection/reset.mdx | 142 + redis/commands/connection/select.mdx | 160 + redis/commands/functions/fcall-ro.mdx | 187 + redis/commands/functions/fcall.mdx | 180 + redis/commands/functions/function-delete.mdx | 161 + redis/commands/functions/function-flush.mdx | 160 + redis/commands/functions/function-kill.mdx | 158 + redis/commands/functions/function-list.mdx | 178 + redis/commands/functions/function-load.mdx | 182 + redis/commands/functions/function-stats.mdx | 168 + redis/commands/functions/overview.mdx | 17 + redis/commands/generic/copy.mdx | 167 + redis/commands/generic/del.mdx | 164 + redis/commands/generic/dump.mdx | 156 + redis/commands/generic/exists.mdx | 167 + redis/commands/generic/expire.mdx | 173 + redis/commands/generic/expireat.mdx | 174 + redis/commands/generic/expiretime.mdx | 160 + redis/commands/generic/keys.mdx | 169 + redis/commands/generic/memory-usage.mdx | 165 + redis/commands/generic/overview.mdx | 34 + redis/commands/generic/persist.mdx | 164 + redis/commands/generic/pexpire.mdx | 172 + redis/commands/generic/pexpireat.mdx | 174 + redis/commands/generic/pexpiretime.mdx | 160 + redis/commands/generic/pttl.mdx | 168 + redis/commands/generic/randomkey.mdx | 162 + redis/commands/generic/rename.mdx | 165 + redis/commands/generic/renamenx.mdx | 165 + redis/commands/generic/restore.mdx | 169 + redis/commands/generic/scan.mdx | 172 + redis/commands/generic/touch.mdx | 164 + redis/commands/generic/ttl.mdx | 168 + redis/commands/generic/type.mdx | 166 + redis/commands/generic/unlink.mdx | 164 + redis/commands/generic/wait.mdx | 164 + redis/commands/generic/waitaof.mdx | 166 + redis/commands/geo/geoadd.mdx | 178 + redis/commands/geo/geodist.mdx | 173 + redis/commands/geo/geohash.mdx | 165 + redis/commands/geo/geopos.mdx | 165 + redis/commands/geo/georadius-ro.mdx | 173 + redis/commands/geo/georadius.mdx | 174 + redis/commands/geo/georadiusbymember-ro.mdx | 171 + redis/commands/geo/georadiusbymember.mdx | 172 + redis/commands/geo/geosearch.mdx | 179 + redis/commands/geo/geosearchstore.mdx | 180 + redis/commands/geo/overview.mdx | 19 + redis/commands/hash/hdel.mdx | 166 + redis/commands/hash/hexists.mdx | 168 + redis/commands/hash/hexpire.mdx | 175 + redis/commands/hash/hexpireat.mdx | 175 + redis/commands/hash/hexpiretime.mdx | 172 + redis/commands/hash/hget.mdx | 167 + redis/commands/hash/hgetall.mdx | 173 + redis/commands/hash/hgetdel.mdx | 174 + redis/commands/hash/hgetex.mdx | 170 + redis/commands/hash/hincrby.mdx | 170 + redis/commands/hash/hincrbyfloat.mdx | 174 + redis/commands/hash/hkeys.mdx | 169 + redis/commands/hash/hlen.mdx | 169 + redis/commands/hash/hmget.mdx | 171 + redis/commands/hash/hmset.mdx | 165 + redis/commands/hash/hpersist.mdx | 170 + redis/commands/hash/hpexpire.mdx | 175 + redis/commands/hash/hpexpireat.mdx | 175 + redis/commands/hash/hpexpiretime.mdx | 173 + redis/commands/hash/hpttl.mdx | 173 + redis/commands/hash/hrandfield.mdx | 175 + redis/commands/hash/hscan.mdx | 181 + redis/commands/hash/hset.mdx | 169 + redis/commands/hash/hsetex.mdx | 175 + redis/commands/hash/hsetnx.mdx | 166 + redis/commands/hash/hstrlen.mdx | 166 + redis/commands/hash/httl.mdx | 173 + redis/commands/hash/hvals.mdx | 169 + redis/commands/hash/overview.mdx | 37 + redis/commands/hyperloglog/overview.mdx | 12 + redis/commands/hyperloglog/pfadd.mdx | 165 + redis/commands/hyperloglog/pfcount.mdx | 164 + redis/commands/hyperloglog/pfmerge.mdx | 165 + redis/commands/json/json-arrappend.mdx | 171 + redis/commands/json/json-arrindex.mdx | 173 + redis/commands/json/json-arrinsert.mdx | 172 + redis/commands/json/json-arrlen.mdx | 170 + redis/commands/json/json-arrpop.mdx | 171 + redis/commands/json/json-arrtrim.mdx | 172 + redis/commands/json/json-clear.mdx | 170 + redis/commands/json/json-debug.mdx | 167 + redis/commands/json/json-del.mdx | 170 + redis/commands/json/json-forget.mdx | 170 + redis/commands/json/json-get.mdx | 173 + redis/commands/json/json-merge.mdx | 173 + redis/commands/json/json-mget.mdx | 170 + redis/commands/json/json-mset.mdx | 175 + redis/commands/json/json-numincrby.mdx | 171 + redis/commands/json/json-nummultby.mdx | 175 + redis/commands/json/json-objkeys.mdx | 170 + redis/commands/json/json-objlen.mdx | 170 + redis/commands/json/json-resp.mdx | 173 + redis/commands/json/json-set.mdx | 172 + redis/commands/json/json-strappend.mdx | 171 + redis/commands/json/json-strlen.mdx | 170 + redis/commands/json/json-toggle.mdx | 170 + redis/commands/json/json-type.mdx | 170 + redis/commands/json/overview.mdx | 35 + redis/commands/list/blmove.mdx | 169 + redis/commands/list/blmpop.mdx | 168 + redis/commands/list/blpop.mdx | 163 + redis/commands/list/brpop.mdx | 163 + redis/commands/list/brpoplpush.mdx | 165 + redis/commands/list/lindex.mdx | 167 + redis/commands/list/linsert.mdx | 168 + redis/commands/list/llen.mdx | 166 + redis/commands/list/lmove.mdx | 168 + redis/commands/list/lmpop.mdx | 165 + redis/commands/list/lpop.mdx | 167 + redis/commands/list/lpos.mdx | 171 + redis/commands/list/lpush.mdx | 168 + redis/commands/list/lpushx.mdx | 167 + redis/commands/list/lrange.mdx | 168 + redis/commands/list/lrem.mdx | 168 + redis/commands/list/lset.mdx | 169 + redis/commands/list/ltrim.mdx | 168 + redis/commands/list/overview.mdx | 31 + redis/commands/list/rpop.mdx | 167 + redis/commands/list/rpoplpush.mdx | 161 + redis/commands/list/rpush.mdx | 168 + redis/commands/list/rpushx.mdx | 167 + redis/commands/overview.mdx | 28 + redis/commands/pub-sub/overview.mdx | 15 + redis/commands/pub-sub/psubscribe.mdx | 153 + redis/commands/pub-sub/publish.mdx | 165 + redis/commands/pub-sub/pubsub.mdx | 161 + redis/commands/pub-sub/punsubscribe.mdx | 147 + redis/commands/pub-sub/subscribe.mdx | 153 + redis/commands/pub-sub/unsubscribe.mdx | 147 + redis/commands/scripting/eval-ro.mdx | 176 + redis/commands/scripting/eval.mdx | 176 + redis/commands/scripting/evalsha-ro.mdx | 173 + redis/commands/scripting/evalsha.mdx | 173 + redis/commands/scripting/overview.mdx | 17 + redis/commands/scripting/script-exists.mdx | 168 + redis/commands/scripting/script-flush.mdx | 164 + redis/commands/scripting/script-kill.mdx | 159 + redis/commands/scripting/script-load.mdx | 169 + redis/commands/search/overview.mdx | 55 + redis/commands/search/search-aggregate.mdx | 123 + redis/commands/search/search-aliasadd.mdx | 106 + redis/commands/search/search-aliasdel.mdx | 92 + redis/commands/search/search-count.mdx | 112 + redis/commands/search/search-create.mdx | 165 + redis/commands/search/search-describe.mdx | 122 + redis/commands/search/search-drop.mdx | 98 + redis/commands/search/search-listaliases.mdx | 98 + redis/commands/search/search-listindexes.mdx | 140 + redis/commands/search/search-query.mdx | 167 + redis/commands/search/search-reindex.mdx | 48 + redis/commands/search/search-waitindexing.mdx | 104 + redis/commands/server/acl.mdx | 178 + redis/commands/server/command.mdx | 158 + redis/commands/server/config-get.mdx | 163 + redis/commands/server/config-set.mdx | 165 + redis/commands/server/dbsize.mdx | 167 + redis/commands/server/flushall.mdx | 170 + redis/commands/server/flushdb.mdx | 170 + redis/commands/server/info.mdx | 162 + redis/commands/server/monitor.mdx | 126 + redis/commands/server/overview.mdx | 19 + redis/commands/server/time.mdx | 162 + redis/commands/set/overview.mdx | 26 + redis/commands/set/sadd.mdx | 169 + redis/commands/set/scard.mdx | 166 + redis/commands/set/sdiff.mdx | 167 + redis/commands/set/sdiffstore.mdx | 168 + redis/commands/set/sinter.mdx | 167 + redis/commands/set/sintercard.mdx | 167 + redis/commands/set/sinterstore.mdx | 167 + redis/commands/set/sismember.mdx | 167 + redis/commands/set/smembers.mdx | 166 + redis/commands/set/smismember.mdx | 167 + redis/commands/set/smove.mdx | 170 + redis/commands/set/spop.mdx | 167 + redis/commands/set/srandmember.mdx | 167 + redis/commands/set/srem.mdx | 167 + redis/commands/set/sscan.mdx | 176 + redis/commands/set/sunion.mdx | 167 + redis/commands/set/sunionstore.mdx | 167 + redis/commands/sorted-set/bzmpop.mdx | 168 + redis/commands/sorted-set/bzpopmax.mdx | 163 + redis/commands/sorted-set/bzpopmin.mdx | 163 + redis/commands/sorted-set/overview.mdx | 44 + redis/commands/sorted-set/zadd.mdx | 178 + redis/commands/sorted-set/zcard.mdx | 169 + redis/commands/sorted-set/zcount.mdx | 171 + redis/commands/sorted-set/zdiff.mdx | 169 + redis/commands/sorted-set/zdiffstore.mdx | 172 + redis/commands/sorted-set/zincrby.mdx | 172 + redis/commands/sorted-set/zinter.mdx | 171 + redis/commands/sorted-set/zintercard.mdx | 159 + redis/commands/sorted-set/zinterstore.mdx | 183 + redis/commands/sorted-set/zlexcount.mdx | 171 + redis/commands/sorted-set/zmpop.mdx | 165 + redis/commands/sorted-set/zmscore.mdx | 177 + redis/commands/sorted-set/zpopmax.mdx | 169 + redis/commands/sorted-set/zpopmin.mdx | 169 + redis/commands/sorted-set/zrandmember.mdx | 165 + redis/commands/sorted-set/zrange.mdx | 180 + redis/commands/sorted-set/zrangebylex.mdx | 163 + redis/commands/sorted-set/zrangebyscore.mdx | 168 + redis/commands/sorted-set/zrangestore.mdx | 169 + redis/commands/sorted-set/zrank.mdx | 170 + redis/commands/sorted-set/zrem.mdx | 165 + redis/commands/sorted-set/zremrangebylex.mdx | 166 + redis/commands/sorted-set/zremrangebyrank.mdx | 166 + .../commands/sorted-set/zremrangebyscore.mdx | 166 + redis/commands/sorted-set/zrevrange.mdx | 167 + redis/commands/sorted-set/zrevrangebylex.mdx | 163 + .../commands/sorted-set/zrevrangebyscore.mdx | 168 + redis/commands/sorted-set/zrevrank.mdx | 170 + redis/commands/sorted-set/zscan.mdx | 183 + redis/commands/sorted-set/zscore.mdx | 177 + redis/commands/sorted-set/zunion.mdx | 174 + redis/commands/sorted-set/zunionstore.mdx | 183 + redis/commands/streams/overview.mdx | 27 + redis/commands/streams/xack.mdx | 166 + redis/commands/streams/xackdel.mdx | 169 + redis/commands/streams/xadd.mdx | 169 + redis/commands/streams/xautoclaim.mdx | 181 + redis/commands/streams/xclaim.mdx | 181 + redis/commands/streams/xdel.mdx | 165 + redis/commands/streams/xdelex.mdx | 168 + redis/commands/streams/xgroup.mdx | 178 + redis/commands/streams/xinfo-consumers.mdx | 168 + redis/commands/streams/xinfo-groups.mdx | 164 + redis/commands/streams/xinfo-stream.mdx | 157 + redis/commands/streams/xlen.mdx | 164 + redis/commands/streams/xpending.mdx | 166 + redis/commands/streams/xrange.mdx | 167 + redis/commands/streams/xread.mdx | 171 + redis/commands/streams/xreadgroup.mdx | 178 + redis/commands/streams/xrevrange.mdx | 167 + redis/commands/streams/xtrim.mdx | 169 + redis/commands/string/append.mdx | 166 + redis/commands/string/decr.mdx | 166 + redis/commands/string/decrby.mdx | 167 + redis/commands/string/delex.mdx | 163 + redis/commands/string/digest.mdx | 161 + redis/commands/string/get.mdx | 173 + redis/commands/string/getdel.mdx | 169 + redis/commands/string/getex.mdx | 165 + redis/commands/string/getrange.mdx | 170 + redis/commands/string/getset.mdx | 165 + redis/commands/string/incr.mdx | 166 + redis/commands/string/incrby.mdx | 167 + redis/commands/string/incrbyfloat.mdx | 171 + redis/commands/string/mget.mdx | 169 + redis/commands/string/mset.mdx | 168 + redis/commands/string/msetnx.mdx | 167 + redis/commands/string/overview.mdx | 31 + redis/commands/string/psetex.mdx | 167 + redis/commands/string/set.mdx | 174 + redis/commands/string/setex.mdx | 167 + redis/commands/string/setnx.mdx | 165 + redis/commands/string/setrange.mdx | 170 + redis/commands/string/strlen.mdx | 166 + redis/commands/transactions/discard.mdx | 125 + redis/commands/transactions/exec.mdx | 127 + redis/commands/transactions/multi.mdx | 127 + redis/commands/transactions/overview.mdx | 14 + redis/commands/transactions/unwatch.mdx | 126 + redis/commands/transactions/watch.mdx | 138 + redis/overall/changelog.mdx | 16 +- redis/overall/compatibility.mdx | 364 +- .../bucket-aggregations/terms.mdx | 2 +- redis/search/aggregations.mdx | 2 + redis/search/aliases.mdx | 6 +- redis/search/command-reference.mdx | 320 +- redis/search/counting.mdx | 2 +- redis/search/document-updates.mdx | 2 +- redis/search/index-management.mdx | 13 +- redis/search/querying.mdx | 4 +- redis/search/schema-definition.mdx | 2 + 306 files changed, 91223 insertions(+), 1389 deletions(-) create mode 100644 redis/commands/bitmap/bitcount.mdx create mode 100644 redis/commands/bitmap/bitfield-ro.mdx create mode 100644 redis/commands/bitmap/bitfield.mdx create mode 100644 redis/commands/bitmap/bitop.mdx create mode 100644 redis/commands/bitmap/bitpos.mdx create mode 100644 redis/commands/bitmap/getbit.mdx create mode 100644 redis/commands/bitmap/overview.mdx create mode 100644 redis/commands/bitmap/setbit.mdx create mode 100644 redis/commands/connection/auth.mdx create mode 100644 redis/commands/connection/client-getname.mdx create mode 100644 redis/commands/connection/client-id.mdx create mode 100644 redis/commands/connection/client-info.mdx create mode 100644 redis/commands/connection/client-list.mdx create mode 100644 redis/commands/connection/client-setinfo.mdx create mode 100644 redis/commands/connection/client-setname.mdx create mode 100644 redis/commands/connection/echo.mdx create mode 100644 redis/commands/connection/hello.mdx create mode 100644 redis/commands/connection/overview.mdx create mode 100644 redis/commands/connection/ping.mdx create mode 100644 redis/commands/connection/quit.mdx create mode 100644 redis/commands/connection/reset.mdx create mode 100644 redis/commands/connection/select.mdx create mode 100644 redis/commands/functions/fcall-ro.mdx create mode 100644 redis/commands/functions/fcall.mdx create mode 100644 redis/commands/functions/function-delete.mdx create mode 100644 redis/commands/functions/function-flush.mdx create mode 100644 redis/commands/functions/function-kill.mdx create mode 100644 redis/commands/functions/function-list.mdx create mode 100644 redis/commands/functions/function-load.mdx create mode 100644 redis/commands/functions/function-stats.mdx create mode 100644 redis/commands/functions/overview.mdx create mode 100644 redis/commands/generic/copy.mdx create mode 100644 redis/commands/generic/del.mdx create mode 100644 redis/commands/generic/dump.mdx create mode 100644 redis/commands/generic/exists.mdx create mode 100644 redis/commands/generic/expire.mdx create mode 100644 redis/commands/generic/expireat.mdx create mode 100644 redis/commands/generic/expiretime.mdx create mode 100644 redis/commands/generic/keys.mdx create mode 100644 redis/commands/generic/memory-usage.mdx create mode 100644 redis/commands/generic/overview.mdx create mode 100644 redis/commands/generic/persist.mdx create mode 100644 redis/commands/generic/pexpire.mdx create mode 100644 redis/commands/generic/pexpireat.mdx create mode 100644 redis/commands/generic/pexpiretime.mdx create mode 100644 redis/commands/generic/pttl.mdx create mode 100644 redis/commands/generic/randomkey.mdx create mode 100644 redis/commands/generic/rename.mdx create mode 100644 redis/commands/generic/renamenx.mdx create mode 100644 redis/commands/generic/restore.mdx create mode 100644 redis/commands/generic/scan.mdx create mode 100644 redis/commands/generic/touch.mdx create mode 100644 redis/commands/generic/ttl.mdx create mode 100644 redis/commands/generic/type.mdx create mode 100644 redis/commands/generic/unlink.mdx create mode 100644 redis/commands/generic/wait.mdx create mode 100644 redis/commands/generic/waitaof.mdx create mode 100644 redis/commands/geo/geoadd.mdx create mode 100644 redis/commands/geo/geodist.mdx create mode 100644 redis/commands/geo/geohash.mdx create mode 100644 redis/commands/geo/geopos.mdx create mode 100644 redis/commands/geo/georadius-ro.mdx create mode 100644 redis/commands/geo/georadius.mdx create mode 100644 redis/commands/geo/georadiusbymember-ro.mdx create mode 100644 redis/commands/geo/georadiusbymember.mdx create mode 100644 redis/commands/geo/geosearch.mdx create mode 100644 redis/commands/geo/geosearchstore.mdx create mode 100644 redis/commands/geo/overview.mdx create mode 100644 redis/commands/hash/hdel.mdx create mode 100644 redis/commands/hash/hexists.mdx create mode 100644 redis/commands/hash/hexpire.mdx create mode 100644 redis/commands/hash/hexpireat.mdx create mode 100644 redis/commands/hash/hexpiretime.mdx create mode 100644 redis/commands/hash/hget.mdx create mode 100644 redis/commands/hash/hgetall.mdx create mode 100644 redis/commands/hash/hgetdel.mdx create mode 100644 redis/commands/hash/hgetex.mdx create mode 100644 redis/commands/hash/hincrby.mdx create mode 100644 redis/commands/hash/hincrbyfloat.mdx create mode 100644 redis/commands/hash/hkeys.mdx create mode 100644 redis/commands/hash/hlen.mdx create mode 100644 redis/commands/hash/hmget.mdx create mode 100644 redis/commands/hash/hmset.mdx create mode 100644 redis/commands/hash/hpersist.mdx create mode 100644 redis/commands/hash/hpexpire.mdx create mode 100644 redis/commands/hash/hpexpireat.mdx create mode 100644 redis/commands/hash/hpexpiretime.mdx create mode 100644 redis/commands/hash/hpttl.mdx create mode 100644 redis/commands/hash/hrandfield.mdx create mode 100644 redis/commands/hash/hscan.mdx create mode 100644 redis/commands/hash/hset.mdx create mode 100644 redis/commands/hash/hsetex.mdx create mode 100644 redis/commands/hash/hsetnx.mdx create mode 100644 redis/commands/hash/hstrlen.mdx create mode 100644 redis/commands/hash/httl.mdx create mode 100644 redis/commands/hash/hvals.mdx create mode 100644 redis/commands/hash/overview.mdx create mode 100644 redis/commands/hyperloglog/overview.mdx create mode 100644 redis/commands/hyperloglog/pfadd.mdx create mode 100644 redis/commands/hyperloglog/pfcount.mdx create mode 100644 redis/commands/hyperloglog/pfmerge.mdx create mode 100644 redis/commands/json/json-arrappend.mdx create mode 100644 redis/commands/json/json-arrindex.mdx create mode 100644 redis/commands/json/json-arrinsert.mdx create mode 100644 redis/commands/json/json-arrlen.mdx create mode 100644 redis/commands/json/json-arrpop.mdx create mode 100644 redis/commands/json/json-arrtrim.mdx create mode 100644 redis/commands/json/json-clear.mdx create mode 100644 redis/commands/json/json-debug.mdx create mode 100644 redis/commands/json/json-del.mdx create mode 100644 redis/commands/json/json-forget.mdx create mode 100644 redis/commands/json/json-get.mdx create mode 100644 redis/commands/json/json-merge.mdx create mode 100644 redis/commands/json/json-mget.mdx create mode 100644 redis/commands/json/json-mset.mdx create mode 100644 redis/commands/json/json-numincrby.mdx create mode 100644 redis/commands/json/json-nummultby.mdx create mode 100644 redis/commands/json/json-objkeys.mdx create mode 100644 redis/commands/json/json-objlen.mdx create mode 100644 redis/commands/json/json-resp.mdx create mode 100644 redis/commands/json/json-set.mdx create mode 100644 redis/commands/json/json-strappend.mdx create mode 100644 redis/commands/json/json-strlen.mdx create mode 100644 redis/commands/json/json-toggle.mdx create mode 100644 redis/commands/json/json-type.mdx create mode 100644 redis/commands/json/overview.mdx create mode 100644 redis/commands/list/blmove.mdx create mode 100644 redis/commands/list/blmpop.mdx create mode 100644 redis/commands/list/blpop.mdx create mode 100644 redis/commands/list/brpop.mdx create mode 100644 redis/commands/list/brpoplpush.mdx create mode 100644 redis/commands/list/lindex.mdx create mode 100644 redis/commands/list/linsert.mdx create mode 100644 redis/commands/list/llen.mdx create mode 100644 redis/commands/list/lmove.mdx create mode 100644 redis/commands/list/lmpop.mdx create mode 100644 redis/commands/list/lpop.mdx create mode 100644 redis/commands/list/lpos.mdx create mode 100644 redis/commands/list/lpush.mdx create mode 100644 redis/commands/list/lpushx.mdx create mode 100644 redis/commands/list/lrange.mdx create mode 100644 redis/commands/list/lrem.mdx create mode 100644 redis/commands/list/lset.mdx create mode 100644 redis/commands/list/ltrim.mdx create mode 100644 redis/commands/list/overview.mdx create mode 100644 redis/commands/list/rpop.mdx create mode 100644 redis/commands/list/rpoplpush.mdx create mode 100644 redis/commands/list/rpush.mdx create mode 100644 redis/commands/list/rpushx.mdx create mode 100644 redis/commands/overview.mdx create mode 100644 redis/commands/pub-sub/overview.mdx create mode 100644 redis/commands/pub-sub/psubscribe.mdx create mode 100644 redis/commands/pub-sub/publish.mdx create mode 100644 redis/commands/pub-sub/pubsub.mdx create mode 100644 redis/commands/pub-sub/punsubscribe.mdx create mode 100644 redis/commands/pub-sub/subscribe.mdx create mode 100644 redis/commands/pub-sub/unsubscribe.mdx create mode 100644 redis/commands/scripting/eval-ro.mdx create mode 100644 redis/commands/scripting/eval.mdx create mode 100644 redis/commands/scripting/evalsha-ro.mdx create mode 100644 redis/commands/scripting/evalsha.mdx create mode 100644 redis/commands/scripting/overview.mdx create mode 100644 redis/commands/scripting/script-exists.mdx create mode 100644 redis/commands/scripting/script-flush.mdx create mode 100644 redis/commands/scripting/script-kill.mdx create mode 100644 redis/commands/scripting/script-load.mdx create mode 100644 redis/commands/search/overview.mdx create mode 100644 redis/commands/search/search-aggregate.mdx create mode 100644 redis/commands/search/search-aliasadd.mdx create mode 100644 redis/commands/search/search-aliasdel.mdx create mode 100644 redis/commands/search/search-count.mdx create mode 100644 redis/commands/search/search-create.mdx create mode 100644 redis/commands/search/search-describe.mdx create mode 100644 redis/commands/search/search-drop.mdx create mode 100644 redis/commands/search/search-listaliases.mdx create mode 100644 redis/commands/search/search-listindexes.mdx create mode 100644 redis/commands/search/search-query.mdx create mode 100644 redis/commands/search/search-reindex.mdx create mode 100644 redis/commands/search/search-waitindexing.mdx create mode 100644 redis/commands/server/acl.mdx create mode 100644 redis/commands/server/command.mdx create mode 100644 redis/commands/server/config-get.mdx create mode 100644 redis/commands/server/config-set.mdx create mode 100644 redis/commands/server/dbsize.mdx create mode 100644 redis/commands/server/flushall.mdx create mode 100644 redis/commands/server/flushdb.mdx create mode 100644 redis/commands/server/info.mdx create mode 100644 redis/commands/server/monitor.mdx create mode 100644 redis/commands/server/overview.mdx create mode 100644 redis/commands/server/time.mdx create mode 100644 redis/commands/set/overview.mdx create mode 100644 redis/commands/set/sadd.mdx create mode 100644 redis/commands/set/scard.mdx create mode 100644 redis/commands/set/sdiff.mdx create mode 100644 redis/commands/set/sdiffstore.mdx create mode 100644 redis/commands/set/sinter.mdx create mode 100644 redis/commands/set/sintercard.mdx create mode 100644 redis/commands/set/sinterstore.mdx create mode 100644 redis/commands/set/sismember.mdx create mode 100644 redis/commands/set/smembers.mdx create mode 100644 redis/commands/set/smismember.mdx create mode 100644 redis/commands/set/smove.mdx create mode 100644 redis/commands/set/spop.mdx create mode 100644 redis/commands/set/srandmember.mdx create mode 100644 redis/commands/set/srem.mdx create mode 100644 redis/commands/set/sscan.mdx create mode 100644 redis/commands/set/sunion.mdx create mode 100644 redis/commands/set/sunionstore.mdx create mode 100644 redis/commands/sorted-set/bzmpop.mdx create mode 100644 redis/commands/sorted-set/bzpopmax.mdx create mode 100644 redis/commands/sorted-set/bzpopmin.mdx create mode 100644 redis/commands/sorted-set/overview.mdx create mode 100644 redis/commands/sorted-set/zadd.mdx create mode 100644 redis/commands/sorted-set/zcard.mdx create mode 100644 redis/commands/sorted-set/zcount.mdx create mode 100644 redis/commands/sorted-set/zdiff.mdx create mode 100644 redis/commands/sorted-set/zdiffstore.mdx create mode 100644 redis/commands/sorted-set/zincrby.mdx create mode 100644 redis/commands/sorted-set/zinter.mdx create mode 100644 redis/commands/sorted-set/zintercard.mdx create mode 100644 redis/commands/sorted-set/zinterstore.mdx create mode 100644 redis/commands/sorted-set/zlexcount.mdx create mode 100644 redis/commands/sorted-set/zmpop.mdx create mode 100644 redis/commands/sorted-set/zmscore.mdx create mode 100644 redis/commands/sorted-set/zpopmax.mdx create mode 100644 redis/commands/sorted-set/zpopmin.mdx create mode 100644 redis/commands/sorted-set/zrandmember.mdx create mode 100644 redis/commands/sorted-set/zrange.mdx create mode 100644 redis/commands/sorted-set/zrangebylex.mdx create mode 100644 redis/commands/sorted-set/zrangebyscore.mdx create mode 100644 redis/commands/sorted-set/zrangestore.mdx create mode 100644 redis/commands/sorted-set/zrank.mdx create mode 100644 redis/commands/sorted-set/zrem.mdx create mode 100644 redis/commands/sorted-set/zremrangebylex.mdx create mode 100644 redis/commands/sorted-set/zremrangebyrank.mdx create mode 100644 redis/commands/sorted-set/zremrangebyscore.mdx create mode 100644 redis/commands/sorted-set/zrevrange.mdx create mode 100644 redis/commands/sorted-set/zrevrangebylex.mdx create mode 100644 redis/commands/sorted-set/zrevrangebyscore.mdx create mode 100644 redis/commands/sorted-set/zrevrank.mdx create mode 100644 redis/commands/sorted-set/zscan.mdx create mode 100644 redis/commands/sorted-set/zscore.mdx create mode 100644 redis/commands/sorted-set/zunion.mdx create mode 100644 redis/commands/sorted-set/zunionstore.mdx create mode 100644 redis/commands/streams/overview.mdx create mode 100644 redis/commands/streams/xack.mdx create mode 100644 redis/commands/streams/xackdel.mdx create mode 100644 redis/commands/streams/xadd.mdx create mode 100644 redis/commands/streams/xautoclaim.mdx create mode 100644 redis/commands/streams/xclaim.mdx create mode 100644 redis/commands/streams/xdel.mdx create mode 100644 redis/commands/streams/xdelex.mdx create mode 100644 redis/commands/streams/xgroup.mdx create mode 100644 redis/commands/streams/xinfo-consumers.mdx create mode 100644 redis/commands/streams/xinfo-groups.mdx create mode 100644 redis/commands/streams/xinfo-stream.mdx create mode 100644 redis/commands/streams/xlen.mdx create mode 100644 redis/commands/streams/xpending.mdx create mode 100644 redis/commands/streams/xrange.mdx create mode 100644 redis/commands/streams/xread.mdx create mode 100644 redis/commands/streams/xreadgroup.mdx create mode 100644 redis/commands/streams/xrevrange.mdx create mode 100644 redis/commands/streams/xtrim.mdx create mode 100644 redis/commands/string/append.mdx create mode 100644 redis/commands/string/decr.mdx create mode 100644 redis/commands/string/decrby.mdx create mode 100644 redis/commands/string/delex.mdx create mode 100644 redis/commands/string/digest.mdx create mode 100644 redis/commands/string/get.mdx create mode 100644 redis/commands/string/getdel.mdx create mode 100644 redis/commands/string/getex.mdx create mode 100644 redis/commands/string/getrange.mdx create mode 100644 redis/commands/string/getset.mdx create mode 100644 redis/commands/string/incr.mdx create mode 100644 redis/commands/string/incrby.mdx create mode 100644 redis/commands/string/incrbyfloat.mdx create mode 100644 redis/commands/string/mget.mdx create mode 100644 redis/commands/string/mset.mdx create mode 100644 redis/commands/string/msetnx.mdx create mode 100644 redis/commands/string/overview.mdx create mode 100644 redis/commands/string/psetex.mdx create mode 100644 redis/commands/string/set.mdx create mode 100644 redis/commands/string/setex.mdx create mode 100644 redis/commands/string/setnx.mdx create mode 100644 redis/commands/string/setrange.mdx create mode 100644 redis/commands/string/strlen.mdx create mode 100644 redis/commands/transactions/discard.mdx create mode 100644 redis/commands/transactions/exec.mdx create mode 100644 redis/commands/transactions/multi.mdx create mode 100644 redis/commands/transactions/overview.mdx create mode 100644 redis/commands/transactions/unwatch.mdx create mode 100644 redis/commands/transactions/watch.mdx diff --git a/docs.json b/docs.json index 0891e59a6..2ca3cbf5a 100644 --- a/docs.json +++ b/docs.json @@ -939,6 +939,393 @@ ] } ] + }, + { + "group": "Command Reference", + "pages": [ + "redis/commands/overview", + { + "group": "Bitmap", + "pages": [ + "redis/commands/bitmap/overview", + "redis/commands/bitmap/bitcount", + "redis/commands/bitmap/bitfield", + "redis/commands/bitmap/bitfield-ro", + "redis/commands/bitmap/bitop", + "redis/commands/bitmap/bitpos", + "redis/commands/bitmap/getbit", + "redis/commands/bitmap/setbit" + ] + }, + { + "group": "Connection", + "pages": [ + "redis/commands/connection/overview", + "redis/commands/connection/auth", + "redis/commands/connection/client-getname", + "redis/commands/connection/client-id", + "redis/commands/connection/client-info", + "redis/commands/connection/client-list", + "redis/commands/connection/client-setinfo", + "redis/commands/connection/client-setname", + "redis/commands/connection/echo", + "redis/commands/connection/hello", + "redis/commands/connection/ping", + "redis/commands/connection/quit", + "redis/commands/connection/reset", + "redis/commands/connection/select" + ] + }, + { + "group": "Functions", + "pages": [ + "redis/commands/functions/overview", + "redis/commands/functions/fcall", + "redis/commands/functions/fcall-ro", + "redis/commands/functions/function-delete", + "redis/commands/functions/function-flush", + "redis/commands/functions/function-kill", + "redis/commands/functions/function-list", + "redis/commands/functions/function-load", + "redis/commands/functions/function-stats" + ] + }, + { + "group": "Generic", + "pages": [ + "redis/commands/generic/overview", + "redis/commands/generic/copy", + "redis/commands/generic/del", + "redis/commands/generic/dump", + "redis/commands/generic/exists", + "redis/commands/generic/expire", + "redis/commands/generic/expireat", + "redis/commands/generic/expiretime", + "redis/commands/generic/keys", + "redis/commands/generic/memory-usage", + "redis/commands/generic/persist", + "redis/commands/generic/pexpire", + "redis/commands/generic/pexpireat", + "redis/commands/generic/pexpiretime", + "redis/commands/generic/pttl", + "redis/commands/generic/randomkey", + "redis/commands/generic/rename", + "redis/commands/generic/renamenx", + "redis/commands/generic/restore", + "redis/commands/generic/scan", + "redis/commands/generic/touch", + "redis/commands/generic/ttl", + "redis/commands/generic/type", + "redis/commands/generic/unlink", + "redis/commands/generic/wait", + "redis/commands/generic/waitaof" + ] + }, + { + "group": "Geo", + "pages": [ + "redis/commands/geo/overview", + "redis/commands/geo/geoadd", + "redis/commands/geo/geodist", + "redis/commands/geo/geohash", + "redis/commands/geo/geopos", + "redis/commands/geo/georadius", + "redis/commands/geo/georadius-ro", + "redis/commands/geo/georadiusbymember", + "redis/commands/geo/georadiusbymember-ro", + "redis/commands/geo/geosearch", + "redis/commands/geo/geosearchstore" + ] + }, + { + "group": "Hash", + "pages": [ + "redis/commands/hash/overview", + "redis/commands/hash/hdel", + "redis/commands/hash/hexists", + "redis/commands/hash/hexpire", + "redis/commands/hash/hexpireat", + "redis/commands/hash/hexpiretime", + "redis/commands/hash/hget", + "redis/commands/hash/hgetall", + "redis/commands/hash/hgetdel", + "redis/commands/hash/hgetex", + "redis/commands/hash/hincrby", + "redis/commands/hash/hincrbyfloat", + "redis/commands/hash/hkeys", + "redis/commands/hash/hlen", + "redis/commands/hash/hmget", + "redis/commands/hash/hmset", + "redis/commands/hash/hpersist", + "redis/commands/hash/hpexpire", + "redis/commands/hash/hpexpireat", + "redis/commands/hash/hpexpiretime", + "redis/commands/hash/hpttl", + "redis/commands/hash/hrandfield", + "redis/commands/hash/hscan", + "redis/commands/hash/hset", + "redis/commands/hash/hsetex", + "redis/commands/hash/hsetnx", + "redis/commands/hash/hstrlen", + "redis/commands/hash/httl", + "redis/commands/hash/hvals" + ] + }, + { + "group": "HyperLogLog", + "pages": [ + "redis/commands/hyperloglog/overview", + "redis/commands/hyperloglog/pfadd", + "redis/commands/hyperloglog/pfcount", + "redis/commands/hyperloglog/pfmerge" + ] + }, + { + "group": "JSON", + "pages": [ + "redis/commands/json/overview", + "redis/commands/json/json-arrappend", + "redis/commands/json/json-arrindex", + "redis/commands/json/json-arrinsert", + "redis/commands/json/json-arrlen", + "redis/commands/json/json-arrpop", + "redis/commands/json/json-arrtrim", + "redis/commands/json/json-clear", + "redis/commands/json/json-del", + "redis/commands/json/json-debug", + "redis/commands/json/json-forget", + "redis/commands/json/json-get", + "redis/commands/json/json-merge", + "redis/commands/json/json-mget", + "redis/commands/json/json-mset", + "redis/commands/json/json-numincrby", + "redis/commands/json/json-nummultby", + "redis/commands/json/json-objkeys", + "redis/commands/json/json-objlen", + "redis/commands/json/json-resp", + "redis/commands/json/json-set", + "redis/commands/json/json-strappend", + "redis/commands/json/json-strlen", + "redis/commands/json/json-toggle", + "redis/commands/json/json-type" + ] + }, + { + "group": "List", + "pages": [ + "redis/commands/list/overview", + "redis/commands/list/blmove", + "redis/commands/list/blmpop", + "redis/commands/list/blpop", + "redis/commands/list/brpop", + "redis/commands/list/brpoplpush", + "redis/commands/list/lindex", + "redis/commands/list/linsert", + "redis/commands/list/llen", + "redis/commands/list/lmove", + "redis/commands/list/lmpop", + "redis/commands/list/lpop", + "redis/commands/list/lpos", + "redis/commands/list/lpush", + "redis/commands/list/lpushx", + "redis/commands/list/lrange", + "redis/commands/list/lrem", + "redis/commands/list/lset", + "redis/commands/list/ltrim", + "redis/commands/list/rpop", + "redis/commands/list/rpoplpush", + "redis/commands/list/rpush", + "redis/commands/list/rpushx" + ] + }, + { + "group": "Pub/Sub", + "pages": [ + "redis/commands/pub-sub/overview", + "redis/commands/pub-sub/psubscribe", + "redis/commands/pub-sub/publish", + "redis/commands/pub-sub/pubsub", + "redis/commands/pub-sub/punsubscribe", + "redis/commands/pub-sub/subscribe", + "redis/commands/pub-sub/unsubscribe" + ] + }, + { + "group": "Scripting", + "pages": [ + "redis/commands/scripting/overview", + "redis/commands/scripting/eval", + "redis/commands/scripting/eval-ro", + "redis/commands/scripting/evalsha", + "redis/commands/scripting/evalsha-ro", + "redis/commands/scripting/script-exists", + "redis/commands/scripting/script-flush", + "redis/commands/scripting/script-kill", + "redis/commands/scripting/script-load" + ] + }, + { + "group": "Search", + "pages": [ + "redis/commands/search/overview", + "redis/commands/search/search-create", + "redis/commands/search/search-reindex", + "redis/commands/search/search-drop", + "redis/commands/search/search-describe", + "redis/commands/search/search-waitindexing", + "redis/commands/search/search-listindexes", + "redis/commands/search/search-query", + "redis/commands/search/search-count", + "redis/commands/search/search-aggregate", + "redis/commands/search/search-aliasadd", + "redis/commands/search/search-aliasdel", + "redis/commands/search/search-listaliases" + ] + }, + { + "group": "Server", + "pages": [ + "redis/commands/server/overview", + "redis/commands/server/acl", + "redis/commands/server/command", + "redis/commands/server/config-get", + "redis/commands/server/config-set", + "redis/commands/server/dbsize", + "redis/commands/server/flushall", + "redis/commands/server/flushdb", + "redis/commands/server/info", + "redis/commands/server/monitor", + "redis/commands/server/time" + ] + }, + { + "group": "Set", + "pages": [ + "redis/commands/set/overview", + "redis/commands/set/sadd", + "redis/commands/set/scard", + "redis/commands/set/sdiff", + "redis/commands/set/sdiffstore", + "redis/commands/set/sinter", + "redis/commands/set/sintercard", + "redis/commands/set/sinterstore", + "redis/commands/set/sismember", + "redis/commands/set/smembers", + "redis/commands/set/smismember", + "redis/commands/set/smove", + "redis/commands/set/spop", + "redis/commands/set/srandmember", + "redis/commands/set/srem", + "redis/commands/set/sscan", + "redis/commands/set/sunion", + "redis/commands/set/sunionstore" + ] + }, + { + "group": "Sorted Set", + "pages": [ + "redis/commands/sorted-set/overview", + "redis/commands/sorted-set/bzmpop", + "redis/commands/sorted-set/bzpopmax", + "redis/commands/sorted-set/bzpopmin", + "redis/commands/sorted-set/zadd", + "redis/commands/sorted-set/zcard", + "redis/commands/sorted-set/zcount", + "redis/commands/sorted-set/zdiff", + "redis/commands/sorted-set/zdiffstore", + "redis/commands/sorted-set/zincrby", + "redis/commands/sorted-set/zinter", + "redis/commands/sorted-set/zintercard", + "redis/commands/sorted-set/zinterstore", + "redis/commands/sorted-set/zlexcount", + "redis/commands/sorted-set/zmpop", + "redis/commands/sorted-set/zmscore", + "redis/commands/sorted-set/zpopmax", + "redis/commands/sorted-set/zpopmin", + "redis/commands/sorted-set/zrandmember", + "redis/commands/sorted-set/zrange", + "redis/commands/sorted-set/zrangebylex", + "redis/commands/sorted-set/zrangebyscore", + "redis/commands/sorted-set/zrangestore", + "redis/commands/sorted-set/zrank", + "redis/commands/sorted-set/zrem", + "redis/commands/sorted-set/zremrangebylex", + "redis/commands/sorted-set/zremrangebyrank", + "redis/commands/sorted-set/zremrangebyscore", + "redis/commands/sorted-set/zrevrange", + "redis/commands/sorted-set/zrevrangebylex", + "redis/commands/sorted-set/zrevrangebyscore", + "redis/commands/sorted-set/zrevrank", + "redis/commands/sorted-set/zscan", + "redis/commands/sorted-set/zscore", + "redis/commands/sorted-set/zunion", + "redis/commands/sorted-set/zunionstore" + ] + }, + { + "group": "Streams", + "pages": [ + "redis/commands/streams/overview", + "redis/commands/streams/xack", + "redis/commands/streams/xackdel", + "redis/commands/streams/xadd", + "redis/commands/streams/xautoclaim", + "redis/commands/streams/xclaim", + "redis/commands/streams/xdel", + "redis/commands/streams/xdelex", + "redis/commands/streams/xgroup", + "redis/commands/streams/xinfo-consumers", + "redis/commands/streams/xinfo-groups", + "redis/commands/streams/xinfo-stream", + "redis/commands/streams/xlen", + "redis/commands/streams/xpending", + "redis/commands/streams/xrange", + "redis/commands/streams/xread", + "redis/commands/streams/xreadgroup", + "redis/commands/streams/xrevrange", + "redis/commands/streams/xtrim" + ] + }, + { + "group": "String", + "pages": [ + "redis/commands/string/overview", + "redis/commands/string/append", + "redis/commands/string/decr", + "redis/commands/string/decrby", + "redis/commands/string/delex", + "redis/commands/string/digest", + "redis/commands/string/get", + "redis/commands/string/getdel", + "redis/commands/string/getex", + "redis/commands/string/getrange", + "redis/commands/string/getset", + "redis/commands/string/incr", + "redis/commands/string/incrby", + "redis/commands/string/incrbyfloat", + "redis/commands/string/mget", + "redis/commands/string/mset", + "redis/commands/string/msetnx", + "redis/commands/string/psetex", + "redis/commands/string/set", + "redis/commands/string/setex", + "redis/commands/string/setnx", + "redis/commands/string/setrange", + "redis/commands/string/strlen" + ] + }, + { + "group": "Transactions", + "pages": [ + "redis/commands/transactions/overview", + "redis/commands/transactions/discard", + "redis/commands/transactions/exec", + "redis/commands/transactions/multi", + "redis/commands/transactions/unwatch", + "redis/commands/transactions/watch" + ] + } + ] } ] }, @@ -1953,6 +2340,10 @@ "source": "/redis/overall/rediscompatibility", "destination": "/redis/overall/compatibility" }, + { + "source": "/redis/search/command-reference", + "destination": "/redis/commands/search/overview" + }, { "source": "/docs/redis/overall/rediscompatibility", "destination": "/redis/overall/compatibility" diff --git a/llms-full.txt b/llms-full.txt index 8ab508bea..1521fac42 100644 --- a/llms-full.txt +++ b/llms-full.txt @@ -10142,7 +10142,7 @@ To view a more detailed Next.js quick start guide for setting up QStash, refer t It's also possible to schedule a background job to run at a later time using [schedules](/docs/qstash/features/schedules). -If you'd like to invoke another endpoint when the background job is complete, you can use [callbacks](/docs/qstash/features/callbacks). +If you'd like to invoke another endpoint when the background job is complete, you can use [callbacks](/docs/qstash/features/callbacks). # Batching Source: https://upstash.com/docs/qstash/features/batch @@ -10441,7 +10441,7 @@ client.message.batch_json( "messageId": "msg_..." } ] -``` +``` # Callbacks Source: https://upstash.com/docs/qstash/features/callbacks @@ -11496,7 +11496,7 @@ from qstash import QStash client = QStash("") client.queue.get("my-queue") ``` - + # Retry Source: https://upstash.com/docs/qstash/features/retry @@ -16964,6 +16964,45071 @@ For debugging or monitoring purposes, you can use Realtime Dashboard in console. +# BITCOUNT +Source: https://upstash.com/docs/redis/commands/bitmap/bitcount + +Use `BITCOUNT` to count set bits in a string. + +## Syntax + +```redis +BITCOUNT [ [BYTE | BIT]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| ` [BYTE \| BIT]` | No | No | Range to count. Offsets are byte-based unless `BIT` is given; negative offsets count from the end. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const bits = await redis.bitcount(key); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.bitcount("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.bitcount("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.bitCount("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.bitcount("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.BitCount(context.Background(), "my-key", nil).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.bitcount("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.bitcount("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# BITFIELD +Source: https://upstash.com/docs/redis/commands/bitmap/bitfield + +Use `BITFIELD` to perform arbitrary bitfield operations. + +## Syntax + +```redis +BITFIELD [GET | [OVERFLOW WRAP | SAT | FAIL] (SET | INCRBY ) [GET | [OVERFLOW WRAP | SAT | FAIL] (SET | INCRBY ) ...]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `(GET \| [OVERFLOW WRAP \| SAT \| FAIL] (SET \| INCRBY ))` | No | Yes | Choose one form: `GET` (also return the previous value); `OVERFLOW`; `WRAP`; `SAT`; `FAIL`; `SET`; `INCRBY`. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer or null replies, one per subcommand | +| RESP3 | Array of integer or null replies, one per subcommand | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.bitfield("my-key").get("u8", 0).exec(); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.bitfield("my-key").get("u8", 0).execute() +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.bitfield("my-key", "GET", "u8", "0"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.bitField("my-key", [{ operation: "GET", encoding: "u8", offset: 0 }]); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.bitfield("my-key").get("u8", 0).execute() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.BitField(context.Background(), "my-key", "GET", "u8", 0).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.bitfield("my-key", "GET", "u8", "0"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("BITFIELD"); + command.arg("my-key"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# BITFIELD_RO +Source: https://upstash.com/docs/redis/commands/bitmap/bitfield-ro + +Use `BITFIELD_RO` to read one or more bitfield values without modifying the key. + +## Syntax + +```redis +BITFIELD_RO [GET [GET ...]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `GET ` | No | Yes | Read the value at `` using ``, such as `u8` or `i16`. Repeat to read several fields. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer or null replies, one per subcommand | +| RESP3 | Array of integer or null replies, one per subcommand | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.bitfield_ro("my-key").get("u8", 0).execute() +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.bitfield_ro("my-key", "GET", "u8", "0"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.bitFieldRo("my-key", [{ encoding: "u8", offset: 0 }]); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.bitfield_ro("my-key", "u8", 0) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.BitFieldRO(context.Background(), "my-key", "GET", "u8", 0).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.bitfieldReadonly("my-key", "GET", "u8", "0"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("BITFIELD_RO"); + command.arg("my-key"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# BITOP +Source: https://upstash.com/docs/redis/commands/bitmap/bitop + +Use `BITOP` to perform bitwise operations between strings. + +## Syntax + +```redis +BITOP (AND | OR | XOR | NOT | DIFF | DIFF1 | ANDOR | ONE) [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `(AND \| OR \| XOR \| NOT \| DIFF \| DIFF1 \| ANDOR \| ONE)` | Yes | No | Choose one form: `AND`; `OR`; `XOR`; `NOT`; `DIFF`; `DIFF1`; `ANDOR`; `ONE`. | +| `` | Yes | No | Redis key used as destkey. | +| `` | Yes | Yes | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +// AND operation +await redis.bitop("and", "destKey", "sourceKey1", "sourceKey2"); + +// OR operation +await redis.bitop("or", "destKey", "sourceKey1", "sourceKey2"); + +// XOR operation +await redis.bitop("xor", "destKey", "sourceKey1", "sourceKey2"); + +// NOT operation (only accepts one source key) +await redis.bitop("not", "destKey", "sourceKey"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.bitop("AND", "destination-key", "source-key-1", "source-key-2") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.bitop("AND", "destination-key", "source-key-1", "source-key-2"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.bitOp("AND", "destination-key", ["source-key-1", "source-key-2"]); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.bitop("AND", "destination-key", "source-key-1", "source-key-2") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.BitOpAnd(context.Background(), "destination-key", "source-key-1", "source-key-2").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.bitop(redis.clients.jedis.args.BitOP.AND, "destination-key", "source-key-1", "source-key-2"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.bit_and("destination-key", &["source-key-1", "source-key-2"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# BITPOS +Source: https://upstash.com/docs/redis/commands/bitmap/bitpos + +Use `BITPOS` to find first bit set or clear in a string. + +## Syntax + +```redis +BITPOS [ [ [BYTE | BIT]]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Bit value to look for: `0` or `1`. | +| ` [ [BYTE \| BIT]]` | No | No | Range to search. Offsets are byte-based unless `BIT` is given; negative offsets count from the end. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: the position of the first matching bit, or `-1` | +| RESP3 | Integer: the position of the first matching bit, or `-1` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.bitpos("key", 1); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.bitpos("my-key", 1) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.bitpos("my-key", "1"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.bitPos("my-key", 1); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.bitpos("my-key", 1) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.BitPos(context.Background(), "my-key", 1).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.bitpos("my-key", true); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("BITPOS"); + command.arg("my-key"); + command.arg("1"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# GETBIT +Source: https://upstash.com/docs/redis/commands/bitmap/getbit + +Use `GETBIT` to get the bit value at offset. + +## Syntax + +```redis +GETBIT +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Zero-based bit offset to read. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: the bit at the offset, `0` or `1` | +| RESP3 | Integer: the bit at the offset, `0` or `1` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const bit = await redis.getbit(key, 4); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.getbit("my-key", 0) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.getbit("my-key", "0"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.getBit("my-key", 0); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.getbit("my-key", 0) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.GetBit(context.Background(), "my-key", 0).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.getbit("my-key", 0); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.getbit("my-key", 0)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# Bitmap commands +Source: https://upstash.com/docs/redis/commands/bitmap/overview + + +Count set bits in a string +Perform arbitrary bitfield operations +Read-only bitfield operations +Perform bitwise operations between strings +Find first bit set or clear in a string +Get the bit value at offset +Set or clear the bit at offset + + +# SETBIT +Source: https://upstash.com/docs/redis/commands/bitmap/setbit + +Use `SETBIT` to set or clear the bit at offset. + +## Syntax + +```redis +SETBIT +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Zero-based bit offset to write. | +| `` | Yes | No | Bit value to write: `0` or `1`. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: the previous bit at the offset, `0` or `1` | +| RESP3 | Integer: the previous bit at the offset, `0` or `1` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const originalBit = await redis.setbit(key, 4, 1); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.setbit("my-key", 0, 1) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.setbit("my-key", "0", "1"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.setBit("my-key", 0, 1); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.setbit("my-key", 0, 1) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.SetBit(context.Background(), "my-key", 0, 1).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.setbit("my-key", 0, true); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.setbit("my-key", 0, true)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# AUTH +Source: https://upstash.com/docs/redis/commands/connection/auth + +Use `AUTH` to authenticate to the server. + +## Syntax + +```redis +AUTH [] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | No | No | Username to authenticate as. | +| `` | Yes | No | Password to authenticate with. | + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.auth("password"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.auth({ password: "password" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.auth("password") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Do(context.Background(), "AUTH", "password").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.auth("password"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("AUTH"); + command.arg("password"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# CLIENT GETNAME +Source: https://upstash.com/docs/redis/commands/connection/client-getname + +Use `CLIENT GETNAME` to get the current connection name. + +## Syntax + +```redis +CLIENT GETNAME +``` + +## Arguments + +This command takes no arguments. + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. +* This command can expose administrative information or make a broad destructive change. Restrict it to trusted code paths. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Null bulk string or null array or Bulk string | +| RESP3 | Null or Bulk string | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.client("GETNAME"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.clientGetName(); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.client_getname() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.ClientGetName(context.Background()).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.clientGetname(); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("CLIENT"); + command.arg("GETNAME"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# CLIENT ID +Source: https://upstash.com/docs/redis/commands/connection/client-id + +Use `CLIENT ID` to get the current client ID. + +## Syntax + +```redis +CLIENT ID +``` + +## Arguments + +This command takes no arguments. + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. +* This command can expose administrative information or make a broad destructive change. Restrict it to trusted code paths. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.client("ID"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.clientId(); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.client_id() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.ClientID(context.Background()).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.clientId(); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("CLIENT"); + command.arg("ID"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# CLIENT INFO +Source: https://upstash.com/docs/redis/commands/connection/client-info + +Use `CLIENT INFO` to get info about current connection. + +## Syntax + +```redis +CLIENT INFO +``` + +## Arguments + +This command takes no arguments. + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. +* This command can expose administrative information or make a broad destructive change. Restrict it to trusted code paths. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string | +| RESP3 | Bulk string | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.client("INFO"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.clientInfo(); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.client_info() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.ClientInfo(context.Background()).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.clientInfo(); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("CLIENT"); + command.arg("INFO"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# CLIENT LIST +Source: https://upstash.com/docs/redis/commands/connection/client-list + +Use `CLIENT LIST` to list all client connections. + +## Syntax + +```redis +CLIENT LIST +``` + +## Arguments + +This command takes no arguments. + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. +* This command can expose administrative information or make a broad destructive change. Restrict it to trusted code paths. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string | +| RESP3 | Bulk string | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.client("LIST"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.clientList(); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.client_list() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.ClientList(context.Background()).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.clientList(); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("CLIENT"); + command.arg("LIST"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# CLIENT SETINFO +Source: https://upstash.com/docs/redis/commands/connection/client-setinfo + +Use `CLIENT SETINFO` to set client connection attributes. + +## Syntax + +```redis +CLIENT SETINFO +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `LIB-NAME \| LIB-VER` | Yes | No | Attribute to update: the client library name or version. | +| `value` | Yes | No | Value to store for the selected client attribute. | + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. +* This command can expose administrative information or make a broad destructive change. Restrict it to trusted code paths. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("CLIENT", "SETINFO", "LIB-NAME", "my-client"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.sendCommand(["CLIENT", "SETINFO", "LIB-NAME", "my-client"]); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.client_setinfo("LIB-NAME", "my-client") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Do(context.Background(), "CLIENT", "SETINFO", "LIB-NAME", "my-client").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.clientSetInfo(redis.clients.jedis.args.ClientAttributeOption.LIB_NAME, "my-client"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("CLIENT"); + command.arg("SETINFO"); + command.arg("LIB-NAME"); + command.arg("my-client"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# CLIENT SETNAME +Source: https://upstash.com/docs/redis/commands/connection/client-setname + +Use `CLIENT SETNAME` to set the connection name. + +## Syntax + +```redis +CLIENT SETNAME +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `connection-name` | Yes | No | Name to associate with this TCP connection. | + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. +* This command can expose administrative information or make a broad destructive change. Restrict it to trusted code paths. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.client("SETNAME", "worker-1"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.clientSetName("worker-1"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.client_setname("worker-1") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Do(context.Background(), "CLIENT", "SETNAME", "worker-1").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.clientSetname("worker-1"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("CLIENT"); + command.arg("SETNAME"); + command.arg("worker-1"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# ECHO +Source: https://upstash.com/docs/redis/commands/connection/echo + +Use `ECHO` to echo the given string. + +## Syntax + +```redis +ECHO +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Message payload. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string | +| RESP3 | Bulk string | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const response = await redis.echo("hello world"); +console.log(response); // "hello world" +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.echo("hello") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.echo("hello"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.echo("hello"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.echo("hello") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Echo(context.Background(), "hello").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.echo("hello"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("ECHO"); + command.arg("hello"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HELLO +Source: https://upstash.com/docs/redis/commands/connection/hello + +Use `HELLO` to handshake with Redis protocol. + +## Syntax + +```redis +HELLO [ [AUTH ] [SETNAME ]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| ` [AUTH ] [SETNAME ]` | No | No | Protocol version to switch to, optionally with credentials and a connection name. | + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Flat array of alternating keys and values | +| RESP3 | Map | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hello(); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hello(); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hello() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Do(context.Background(), "HELLO").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; +import java.nio.charset.StandardCharsets; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.commands.ProtocolCommand; + +ProtocolCommand command = () -> "HELLO".getBytes(StandardCharsets.UTF_8); +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.sendCommand(command); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("HELLO"); + + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# Connection commands +Source: https://upstash.com/docs/redis/commands/connection/overview + + +Authenticate to the server +Get the current connection name +Get the current client ID +Get info about current connection +List all client connections +Set client connection attributes +Set the connection name +Echo the given string +Handshake with Redis protocol +Ping the server +Close the connection +Reset the connection +Select the database by index + + +# PING +Source: https://upstash.com/docs/redis/commands/connection/ping + +Use `PING` to ping the server. + +## Syntax + +```redis +PING [] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | No | No | Message payload. | + +## Important points + +* Without arguments the reply is `PONG`; with a message, the message is echoed back as a bulk string. +* While the connection is subscribed under RESP2, `PING` replies with a two-element array holding `pong` and the message instead. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `PONG`, or the message as a bulk string; a two-element `pong`/message array while subscribed | +| RESP3 | Simple string `PONG`, or the message as a bulk string | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const response = await redis.ping(); +console.log(response); // "PONG" +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.ping() +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.ping(); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.ping(); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.ping() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Ping(context.Background()).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.ping(); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("PING"); + + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# QUIT +Source: https://upstash.com/docs/redis/commands/connection/quit + +Use `QUIT` to close the connection. + +## Syntax + +```redis +QUIT +``` + +## Arguments + +This command takes no arguments. + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.quit(); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.sendCommand(["QUIT"]); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.quit() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Quit(context.Background()).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; +import java.nio.charset.StandardCharsets; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.commands.ProtocolCommand; + +ProtocolCommand command = () -> "QUIT".getBytes(StandardCharsets.UTF_8); +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.sendCommand(command); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("QUIT"); + + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# RESET +Source: https://upstash.com/docs/redis/commands/connection/reset + +Use `RESET` to reset the connection. + +## Syntax + +```redis +RESET +``` + +## Arguments + +This command takes no arguments. + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `RESET` | +| RESP3 | Simple string `RESET` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.reset(); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.sendCommand(["RESET"]); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.reset() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Do(context.Background(), "RESET").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.reset(); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("RESET"); + + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# SELECT +Source: https://upstash.com/docs/redis/commands/connection/select + +Use `SELECT` to select the database by index. + +## Syntax + +```redis +SELECT 0 +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `0` | Yes | No | Database index. Upstash supports only database 0. | + +## Important points + +* Upstash exposes a single logical database. Any index other than `0` returns an error. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.select("0"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.sendCommand(["SELECT", "0"]); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.select("0") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Do(context.Background(), "SELECT", "0").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.select(0); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("SELECT"); + command.arg("0"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# FCALL +Source: https://upstash.com/docs/redis/commands/functions/fcall + +Use `FCALL` to call a function. + +## Syntax + +```redis +FCALL [ [ ...]] [ [ ...]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Name of the registered function to call. | +| `` | Yes | No | Number of key arguments that follow. | +| `` | No | Yes | Redis key targeted by the command. | +| `` | No | Yes | Additional argument passed to the function. | + +## Important points + +* `numkeys` must equal the number of key arguments that immediately follow it; remaining arguments are available to the script or function as ordinary arguments. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Reply returned by the invoked function | +| RESP3 | Reply returned by the invoked function | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const code = ` +#!lua name=mylib +redis.register_function('helloworld', + function() + return 'Hello World!' + end +) +`; + +await redis.functions.load({ code, replace: true }); + +const res = await redis.functions.call("helloworld"); +console.log(res); // "Hello World!" +``` + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.fcall("my_function", "1", "my-key", "value"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.fCall("my_function", { keys: ["my-key"], arguments: ["value"] }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.fcall("my_function", 1, "my-key", "value") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.FCall(context.Background(), "my_function", []string{"my-key"}, "value").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.fcall("my_function", java.util.List.of("my-key"), java.util.List.of("value")); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("FCALL"); + command.arg("my_function"); + command.arg("1"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# FCALL_RO +Source: https://upstash.com/docs/redis/commands/functions/fcall-ro + +Use `FCALL_RO` to call a read-only function. + +## Syntax + +```redis +FCALL_RO [ [ ...]] [ [ ...]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Name of the registered function to call. | +| `` | Yes | No | Number of key arguments that follow. | +| `` | No | Yes | Redis key targeted by the command. | +| `` | No | Yes | Additional argument passed to the function. | + +## Important points + +* `numkeys` must equal the number of key arguments that immediately follow it; remaining arguments are available to the script or function as ordinary arguments. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Reply returned by the invoked read-only function | +| RESP3 | Reply returned by the invoked read-only function | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const code = ` +#!lua name=ro_lib + +local function get_value(keys, args) + return redis.call('GET', keys[1]) +end + +redis.register_function({ + function_name='get_value', + callback=get_value, + flags={ 'no-writes' } +}) +`; + +await redis.functions.load({ code, replace: true }); + +// Call the read-only function +// Note: We can modify the keys usage here, but since it represents a read-only operation +// and we marked it with 'no-writes', it is safe to use callRo. +const value = await redis.functions.callRo("get_value", ["mykey"]) +``` + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.fcall_ro("my_function", "1", "my-key", "value"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.fCallRo("my_function", { keys: ["my-key"], arguments: ["value"] }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.fcall_ro("my_function", 1, "my-key", "value") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.FCallRO(context.Background(), "my_function", []string{"my-key"}, "value").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.fcallReadonly("my_function", java.util.List.of("my-key"), java.util.List.of("value")); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("FCALL_RO"); + command.arg("my_function"); + command.arg("1"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# FUNCTION DELETE +Source: https://upstash.com/docs/redis/commands/functions/function-delete + +Use `FUNCTION DELETE` to delete a library. + +## Syntax + +```redis +FUNCTION DELETE +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Name of the function library. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.functions.delete("mylib") +``` + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.function("DELETE", "library-name"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.functionDelete("library-name"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.function_delete("library-name") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.FunctionDelete(context.Background(), "library-name").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.functionDelete("library-name"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("FUNCTION"); + command.arg("DELETE"); + command.arg("library-name"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# FUNCTION FLUSH +Source: https://upstash.com/docs/redis/commands/functions/function-flush + +Use `FUNCTION FLUSH` to delete all libraries. + +## Syntax + +```redis +FUNCTION FLUSH [ASYNC | SYNC] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `(ASYNC \| SYNC)` | No | No | Choose one form: `ASYNC` (request asynchronous cleanup); `SYNC` (request synchronous cleanup). | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.functions.flush() +``` + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.function("FLUSH"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.functionFlush(); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.function_flush() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.FunctionFlush(context.Background()).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.functionFlush(); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("FUNCTION"); + command.arg("FLUSH"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# FUNCTION KILL +Source: https://upstash.com/docs/redis/commands/functions/function-kill + +Use `FUNCTION KILL` to kill a running function. + +## Syntax + +```redis +FUNCTION KILL +``` + +## Arguments + +This command takes no arguments. + +## Important points + +* The current deployment recognizes this command but reports `NOTBUSY` because it does not expose an interruptible running-function state. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Error reply (`NOTBUSY` on the current deployment) | +| RESP3 | Error reply (`NOTBUSY` on the current deployment) | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.function("KILL"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.functionKill(); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.function_kill() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.FunctionKill(context.Background()).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.functionKill(); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("FUNCTION"); + command.arg("KILL"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# FUNCTION LIST +Source: https://upstash.com/docs/redis/commands/functions/function-list + +Use `FUNCTION LIST` to list all libraries. + +## Syntax + +```redis +FUNCTION LIST [LIBRARYNAME ] [WITHCODE] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `LIBRARYNAME ` | No | No | Return only libraries whose name matches this pattern. | +| `WITHCODE` | No | No | Include each library's source code. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of flat arrays containing library metadata | +| RESP3 | Array of maps containing library metadata | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const libs = await redis.functions.list({ + libraryName: "mylib", + withCode: true +}) + +console.log(libs) +// [ +// { +// libraryName: "mylib", +// engine: "LUA", +// functions: [{ +// name: "my_func", +// description: null, +// flags: [ "no-writes" ] +// }], +// libraryCode: "#!lua name=mylib ..." +// } +// ] +``` + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.function("LIST"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.functionList(); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.function_list() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.FunctionList(context.Background(), redis.FunctionListQuery{}).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.functionList(); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("FUNCTION"); + command.arg("LIST"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# FUNCTION LOAD +Source: https://upstash.com/docs/redis/commands/functions/function-load + +Use `FUNCTION LOAD` to load a library. + +## Syntax + +```redis +FUNCTION LOAD [REPLACE] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `REPLACE` | No | No | Allow replacement of an existing destination. | +| `` | Yes | No | Library source, including its `#!lua name=` shebang. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string | +| RESP3 | Bulk string | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const code = `#!lua name=mylib + + -- Simple function that returns a string + redis.register_function( + 'helloworld', + function() return 'Hello World!' end + ) + + -- Complex function that modifies data with logic + local function my_hset(keys, args) + local hash = keys[1] + local time = redis.call('TIME')[1] + return redis.call('HSET', hash, '_last_modified_', time, unpack(args)) + end + + redis.register_function('my_hset', my_hset) +`; + +const libraryName = await redis.functions.load({ code, replace: true }); + +console.log(libraryName); // "mylib" +``` + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.function("LOAD", "function-code"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.functionLoad("function-code"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.function_load("function-code") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.FunctionLoad(context.Background(), "function-code").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.functionLoad("function-code"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("FUNCTION"); + command.arg("LOAD"); + command.arg("function-code"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# FUNCTION STATS +Source: https://upstash.com/docs/redis/commands/functions/function-stats + +Use `FUNCTION STATS` to get function execution stats. + +## Syntax + +```redis +FUNCTION STATS +``` + +## Arguments + +This command takes no arguments. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Flat array of alternating keys and values | +| RESP3 | Map | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const stats = await redis.functions.stats() + +console.log(stats) +// { +// engines: { +// LUA: { +// librariesCount: 3, +// functionsCount: 15 +// } +// } +// } +``` + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.function("STATS"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.functionStats(); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.function_stats() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.FunctionStats(context.Background()).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.functionStats(); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("FUNCTION"); + command.arg("STATS"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# Functions commands +Source: https://upstash.com/docs/redis/commands/functions/overview + + +Call a function +Call a read-only function +Delete a library +Delete all libraries +Kill a running function +List all libraries +Load a library +Get function execution stats + + +# COPY +Source: https://upstash.com/docs/redis/commands/generic/copy + +Use `COPY` to copy a key to another key. + +## Syntax + +```redis +COPY [DB ] [REPLACE] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key used as source. | +| `` | Yes | No | Redis key used as destination. | +| `DB ` | No | No | Index of the database to copy the key into. | +| `REPLACE` | No | No | Allow replacement of an existing destination. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: `1` if the key was copied, `0` otherwise | +| RESP3 | Integer: `1` if the key was copied, `0` otherwise | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.copy("source-key", "destination-key"); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.copy("source-key", "destination-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.copy("source-key", "destination-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.copy("source-key", "destination-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.copy("source-key", "destination-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Copy(context.Background(), "source-key", "destination-key", 0, false).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.copy("source-key", "destination-key", false); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.copy("source-key", "destination-key", redis::CopyOptions::default())?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# DEL +Source: https://upstash.com/docs/redis/commands/generic/del + +Use `DEL` to delete one or more keys. + +## Syntax + +```redis +DEL [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | Yes | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.del("key1", "key2"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.delete("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.del("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.del("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.delete("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Del(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.del("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.del("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# DUMP +Source: https://upstash.com/docs/redis/commands/generic/dump + +Use `DUMP` to serialize a key's value. + +## Syntax + +```redis +DUMP +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string or Null bulk string or null array | +| RESP3 | Bulk string or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.dump("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.dump("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.dump("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Dump(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.dump("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("DUMP"); + command.arg("my-key"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# EXISTS +Source: https://upstash.com/docs/redis/commands/generic/exists + +Use `EXISTS` to check if keys exist. + +## Syntax + +```redis +EXISTS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | Yes | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.set("key1", "value1") +await redis.set("key2", "value2") +const keys = await redis.exists("key1", "key2", "key3"); +console.log(keys) // 2 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.exists("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.exists("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.exists("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.exists("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Exists(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.exists("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.exists("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# EXPIRE +Source: https://upstash.com/docs/redis/commands/generic/expire + +Use `EXPIRE` to set a key's TTL in seconds. + +## Syntax + +```redis +EXPIRE [NX | XX | GT | LT] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Lifetime in seconds. | +| `(NX \| XX \| GT \| LT)` | No | No | Choose one form: `NX` (only when the key has no expiration); `XX` (only when the key already has one); `GT` (only when the new expiration is later than the current one); `LT` (only when it is earlier). | + +## Important points + +* `NX` cannot be combined with `XX`, `GT`, or `LT`, and `GT` and `LT` cannot be used together. +* A key with no expiration counts as an infinite one, so `GT` never sets an expiration on such a key and `LT` always does. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: `1` if the timeout was set, `0` otherwise | +| RESP3 | Integer: `1` if the timeout was set, `0` otherwise | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.set("mykey", "Hello"); +await redis.expire("mykey", 10); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.expire("my-key", 1000) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.expire("my-key", "1000"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.expire("my-key", 1000); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.expire("my-key", 1000) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Expire(context.Background(), "my-key", 1000*time.Second).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.expire("my-key", 1000); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.expire("my-key", 1000)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# EXPIREAT +Source: https://upstash.com/docs/redis/commands/generic/expireat + +Use `EXPIREAT` to set expiry as Unix timestamp. + +## Syntax + +```redis +EXPIREAT [NX | XX | GT | LT] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Expiration time as a Unix timestamp in seconds. | +| `(NX \| XX \| GT \| LT)` | No | No | Choose one form: `NX` (only when the key has no expiration); `XX` (only when the key already has one); `GT` (only when the new expiration is later than the current one); `LT` (only when it is earlier). | + +## Important points + +* `NX` cannot be combined with `XX`, `GT`, or `LT`, and `GT` and `LT` cannot be used together. +* A key with no expiration counts as an infinite one, so `GT` never sets an expiration on such a key and `LT` always does. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: `1` if the timeout was set, `0` otherwise | +| RESP3 | Integer: `1` if the timeout was set, `0` otherwise | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.set("mykey", "Hello"); +const tenSecondsFromNow = Math.floor(Date.now() / 1000) + 10; +await redis.expireat("mykey", tenSecondsFromNow); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.expireat("my-key", 1735689600) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.expireat("my-key", "1735689600"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.expireAt("my-key", 1735689600); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.expireat("my-key", 1735689600) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.ExpireAt(context.Background(), "my-key", time.Unix(1735689600, 0)).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.expireAt("my-key", 1735689600); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.expire_at("my-key", 1735689600)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# EXPIRETIME +Source: https://upstash.com/docs/redis/commands/generic/expiretime + +Use `EXPIRETIME` to get expiry as Unix timestamp. + +## Syntax + +```redis +EXPIRETIME +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | + +## Important points + +* Negative integer replies are sentinel values, not durations or timestamps; see the response description for missing or persistent data. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: expiration Unix time in seconds, `-1` if the key has no expiration, `-2` if the key does not exist | +| RESP3 | Integer: expiration Unix time in seconds, `-1` if the key has no expiration, `-2` if the key does not exist | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.expiretime("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.expireTime("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.expiretime("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.ExpireTime(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.expireTime("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.expire_time("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# KEYS +Source: https://upstash.com/docs/redis/commands/generic/keys + +Use `KEYS` to find keys matching a pattern. + +## Syntax + +```redis +KEYS +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Glob-style pattern to match keys against. | + +## Important points + +* This command can expose administrative information or make a broad destructive change. Restrict it to trusted code paths. +* This operation can inspect a large part of the database. Prefer cursor-based scans where possible and avoid unbounded use on hot paths. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string keys | +| RESP3 | Array of bulk-string keys | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const keys = await redis.keys("prefix*"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.keys("*") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.keys("*"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.keys("*"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.keys("*") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Keys(context.Background(), "*").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.keys("*"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.keys("*")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# MEMORY USAGE +Source: https://upstash.com/docs/redis/commands/generic/memory-usage + +Use `MEMORY USAGE` to estimate memory used by a key. + +## Syntax + +```redis +MEMORY USAGE [SAMPLES ] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | Key whose in-memory footprint should be estimated. | +| `SAMPLES count` | No | No | Sampling count used when estimating large stream values. | + +## Important points + +* The result is an estimate in bytes and can change as the internal representation changes. +* A missing key returns null. The sampling count is clamped to the deployment's supported range. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer or Null bulk string or null array | +| RESP3 | Integer or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.memory("USAGE", "my-key", "SAMPLES", "10"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.memoryUsage("my-key", { SAMPLES: 10 }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.memory_usage("my-key", samples=10) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.MemoryUsage(context.Background(), "my-key", 10).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.memoryUsage("my-key", 10); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("MEMORY"); + command.arg("USAGE"); + command.arg("my-key"); + command.arg("SAMPLES"); + command.arg("10"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# Generic commands +Source: https://upstash.com/docs/redis/commands/generic/overview + + +Copy a key to another key +Delete one or more keys +Serialize a key's value +Check if keys exist +Set a key's TTL in seconds +Set expiry as Unix timestamp +Get expiry as Unix timestamp +Find keys matching a pattern +Estimate memory used by a key +Remove the expiration from a key +Set a key's TTL in milliseconds +Set expiry as Unix ms timestamp +Get expiry as Unix ms timestamp +Get TTL in milliseconds +Return a random key +Rename a key +Rename a key if new key doesn't exist +Deserialize and restore a key +Incrementally iterate keys +Update last access time of keys +Get TTL in seconds +Get the type of a key +Delete keys asynchronously +Wait for replica acknowledgements +Wait for local and replica persistence + + +# PERSIST +Source: https://upstash.com/docs/redis/commands/generic/persist + +Use `PERSIST` to remove the expiration from a key. + +## Syntax + +```redis +PERSIST +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: `1` if the timeout was removed, `0` otherwise | +| RESP3 | Integer: `1` if the timeout was removed, `0` otherwise | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.persist(key); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.persist("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.persist("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.persist("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.persist("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Persist(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.persist("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.persist("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# PEXPIRE +Source: https://upstash.com/docs/redis/commands/generic/pexpire + +Use `PEXPIRE` to set a key's TTL in milliseconds. + +## Syntax + +```redis +PEXPIRE [NX | XX | GT | LT] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Lifetime in milliseconds. | +| `(NX \| XX \| GT \| LT)` | No | No | Choose one form: `NX` (only when the key has no expiration); `XX` (only when the key already has one); `GT` (only when the new expiration is later than the current one); `LT` (only when it is earlier). | + +## Important points + +* `NX` cannot be combined with `XX`, `GT`, or `LT`, and `GT` and `LT` cannot be used together. +* A key with no expiration counts as an infinite one, so `GT` never sets an expiration on such a key and `LT` always does. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: `1` if the timeout was set, `0` otherwise | +| RESP3 | Integer: `1` if the timeout was set, `0` otherwise | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.pexpire(key, 60_000); // 1 minute +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.pexpire("my-key", 1000) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.pexpire("my-key", "1000"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.pExpire("my-key", 1000); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.pexpire("my-key", 1000) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.PExpire(context.Background(), "my-key", time.Second).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.pexpire("my-key", 1000); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.pexpire("my-key", 1000)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# PEXPIREAT +Source: https://upstash.com/docs/redis/commands/generic/pexpireat + +Use `PEXPIREAT` to set expiry as Unix ms timestamp. + +## Syntax + +```redis +PEXPIREAT [NX | XX | GT | LT] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Expiration time as a Unix timestamp in milliseconds. | +| `(NX \| XX \| GT \| LT)` | No | No | Choose one form: `NX` (only when the key has no expiration); `XX` (only when the key already has one); `GT` (only when the new expiration is later than the current one); `LT` (only when it is earlier). | + +## Important points + +* `NX` cannot be combined with `XX`, `GT`, or `LT`, and `GT` and `LT` cannot be used together. +* A key with no expiration counts as an infinite one, so `GT` never sets an expiration on such a key and `LT` always does. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: `1` if the timeout was set, `0` otherwise | +| RESP3 | Integer: `1` if the timeout was set, `0` otherwise | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.set("mykey", "Hello"); +const tenMinutesFromNow = Date.now() + 10 * 60 * 1000; +await redis.pexpireat("mykey", tenMinutesFromNow); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.pexpireat("my-key", 1735689600) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.pexpireat("my-key", "1735689600"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.pExpireAt("my-key", 1735689600); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.pexpireat("my-key", 1735689600) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.PExpireAt(context.Background(), "my-key", time.UnixMilli(1735689600)).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.pexpireAt("my-key", 1735689600); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.pexpire_at("my-key", 1735689600)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# PEXPIRETIME +Source: https://upstash.com/docs/redis/commands/generic/pexpiretime + +Use `PEXPIRETIME` to get expiry as Unix ms timestamp. + +## Syntax + +```redis +PEXPIRETIME +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | + +## Important points + +* Negative integer replies are sentinel values, not durations or timestamps; see the response description for missing or persistent data. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: expiration Unix time in milliseconds, `-1` if the key has no expiration, `-2` if the key does not exist | +| RESP3 | Integer: expiration Unix time in milliseconds, `-1` if the key has no expiration, `-2` if the key does not exist | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.pexpiretime("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.pExpireTime("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.pexpiretime("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.PExpireTime(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.pexpireTime("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.pexpire_time("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# PTTL +Source: https://upstash.com/docs/redis/commands/generic/pttl + +Use `PTTL` to get TTL in milliseconds. + +## Syntax + +```redis +PTTL +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | + +## Important points + +* Negative integer replies are sentinel values, not durations or timestamps; see the response description for missing or persistent data. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: remaining lifetime in milliseconds, `-1` if the key has no expiration, `-2` if the key does not exist | +| RESP3 | Integer: remaining lifetime in milliseconds, `-1` if the key has no expiration, `-2` if the key does not exist | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const millis = await redis.pttl(key); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.pttl("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.pttl("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.pTTL("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.pttl("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.PTTL(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.pttl("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.pttl("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# RANDOMKEY +Source: https://upstash.com/docs/redis/commands/generic/randomkey + +Use `RANDOMKEY` to return a random key. + +## Syntax + +```redis +RANDOMKEY +``` + +## Arguments + +This command takes no arguments. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Null bulk string or null array or Bulk string | +| RESP3 | Null or Bulk string | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const key = await redis.randomkey(); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.randomkey() +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.randomkey(); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.randomKey(); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.randomkey() +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.RandomKey(context.Background()).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.randomKey(); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("RANDOMKEY"); + + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# RENAME +Source: https://upstash.com/docs/redis/commands/generic/rename + +Use `RENAME` to rename a key. + +## Syntax + +```redis +RENAME +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Redis key used as newkey. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.rename("old", "new"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.rename("old-key", "new-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.rename("old-key", "new-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.rename("old-key", "new-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.rename("old-key", "new-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Rename(context.Background(), "old-key", "new-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.rename("old-key", "new-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.rename("old-key", "new-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# RENAMENX +Source: https://upstash.com/docs/redis/commands/generic/renamenx + +Use `RENAMENX` to rename a key if new key doesn't exist. + +## Syntax + +```redis +RENAMENX +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Redis key used as newkey. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: `1` if the key was renamed, `0` if the destination already exists | +| RESP3 | Integer: `1` if the key was renamed, `0` if the destination already exists | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const renamed = await redis.renamenx("old", "new"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.renamenx("old-key", "new-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.renamenx("old-key", "new-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.renameNX("old-key", "new-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.renamenx("old-key", "new-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.RenameNX(context.Background(), "old-key", "new-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.renamenx("old-key", "new-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.rename_nx("old-key", "new-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# RESTORE +Source: https://upstash.com/docs/redis/commands/generic/restore + +Use `RESTORE` to deserialize and restore a key. + +## Syntax + +```redis +RESTORE [REPLACE] [ABSTTL] [IDLETIME ] [FREQ ] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Lifetime in milliseconds; `0` restores the key without an expiration. | +| `` | Yes | No | Payload produced by `DUMP`. | +| `REPLACE` | No | No | Allow replacement of an existing destination. | +| `ABSTTL` | No | No | Treat `` as an absolute Unix timestamp in milliseconds. | +| `IDLETIME ` | No | No | Set the key's idle time, in seconds. | +| `FREQ ` | No | No | Set the key's access frequency counter. | + +## Important points + +* This command can expose administrative information or make a broad destructive change. Restrict it to trusted code paths. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.restore("my-key", "1", "serialized-value"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.restore("my-key", 1, "serialized-value"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.restore("my-key", 1, "serialized-value") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Restore(context.Background(), "my-key", time.Millisecond, "serialized-value").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.restore("my-key", 1, "serialized-value".getBytes()); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("RESTORE"); + command.arg("my-key"); + command.arg("1"); + command.arg("serialized-value"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# SCAN +Source: https://upstash.com/docs/redis/commands/generic/scan + +Use `SCAN` to incrementally iterate keys. + +## Syntax + +```redis +SCAN [MATCH ] [COUNT ] [TYPE ] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Cursor returned by the previous call; start at `0`. | +| `MATCH ` | No | No | Return only elements matching this glob-style pattern. | +| `COUNT ` | No | No | Hint for how much work each iteration should do. | +| `TYPE ` | No | No | Return only keys of this type, such as `string`, `list`, or `hash`. | + +## Important points + +* This operation can inspect a large part of the database. Prefer cursor-based scans where possible and avoid unbounded use on hot paths. +* The cursor is opaque. Start with `0` and continue until the server returns cursor `0`; a single iteration may return no elements. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Two-element array: cursor and array of bulk-string keys | +| RESP3 | Two-element array: cursor and array of bulk-string keys | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const [cursor, keys] = await redis.scan(0, { match: "*" }); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.scan(0) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.scan("0"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.scan("0"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.scan(0) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, _, err := client.Scan(context.Background(), 0, "*", 0).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.scan("0"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("SCAN"); + command.arg("0"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# TOUCH +Source: https://upstash.com/docs/redis/commands/generic/touch + +Use `TOUCH` to update last access time of keys. + +## Syntax + +```redis +TOUCH [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | Yes | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.touch("key1", "key2", "key3"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.touch("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.touch("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.touch("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.touch("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Touch(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.touch("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("TOUCH"); + command.arg("my-key"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# TTL +Source: https://upstash.com/docs/redis/commands/generic/ttl + +Use `TTL` to get TTL in seconds. + +## Syntax + +```redis +TTL +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | + +## Important points + +* Negative integer replies are sentinel values, not durations or timestamps; see the response description for missing or persistent data. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: remaining lifetime in seconds, `-1` if the key has no expiration, `-2` if the key does not exist | +| RESP3 | Integer: remaining lifetime in seconds, `-1` if the key has no expiration, `-2` if the key does not exist | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const seconds = await redis.ttl(key); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.ttl("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.ttl("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.ttl("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.ttl("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.TTL(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.ttl("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.ttl("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# TYPE +Source: https://upstash.com/docs/redis/commands/generic/type + +Use `TYPE` to get the type of a key. + +## Syntax + +```redis +TYPE +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string: the type name, or `none` if the key does not exist | +| RESP3 | Simple string: the type name, or `none` if the key does not exist | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.set("key", "value"); +const t = await redis.type("key"); +console.log(t) // "string" +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.type("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.type("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.type("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.type("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Type(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.type("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.key_type("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# UNLINK +Source: https://upstash.com/docs/redis/commands/generic/unlink + +Use `UNLINK` to delete keys asynchronously. + +## Syntax + +```redis +UNLINK [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | Yes | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.unlink("key1", "key2"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.unlink("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.unlink("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.unlink("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.unlink("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Unlink(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.unlink("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.unlink("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# WAIT +Source: https://upstash.com/docs/redis/commands/generic/wait + +Use `WAIT` to wait for replica acknowledgements. + +## Syntax + +```redis +WAIT +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `numreplicas` | Yes | No | Non-negative number of replicas that should acknowledge prior writes on this connection. | +| `timeout` | Yes | No | Maximum wait in milliseconds; `0` means no timeout. | + +## Important points + +* This deployment waits for writes enqueued before `WAIT` begins, including writes from other connections. That is broader than the per-connection wording used by Redis clients. +* The reply can be lower than `numreplicas` when the timeout expires. This improves observed replication durability but does not make Redis a strongly consistent store. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.wait("1", "1000"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.wait(1, 1000); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.wait("1", "1000") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Wait(context.Background(), 1, time.Second).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.waitReplicas(1, 1000); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("WAIT"); + command.arg("1"); + command.arg("1000"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# WAITAOF +Source: https://upstash.com/docs/redis/commands/generic/waitaof + +Use `WAITAOF` to wait for local and replica persistence. + +## Syntax + +```redis +WAITAOF +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `numlocal` | Yes | No | Whether to wait for local persistence: `0` or `1`. | +| `numreplicas` | Yes | No | Non-negative number of replicas whose append-only files should include prior writes. | +| `timeout` | Yes | No | Maximum wait in milliseconds; `0` means no timeout. | + +## Important points + +* This deployment waits for writes enqueued before `WAITAOF` begins, including writes from other connections. +* The two-element reply contains the local persistence acknowledgement first and the replica persistence count second. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Two-element array of integers: local and replica acknowledgments | +| RESP3 | Two-element array of integers: local and replica acknowledgments | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("WAITAOF", "1", "1", "1000"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.sendCommand(["WAITAOF", "1", "1", "1000"]); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.waitaof("1", "1", "1000") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.WaitAOF(context.Background(), 1, 1, time.Second).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.waitAOF(1, 1, 1000); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("WAITAOF"); + command.arg("1"); + command.arg("1"); + command.arg("1000"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# GEOADD +Source: https://upstash.com/docs/redis/commands/geo/geoadd + +Use `GEOADD` to add geospatial items. + +## Syntax + +```redis +GEOADD [NX | XX] [CH] [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `(NX \| XX)` | No | No | Choose one form: `NX` (only add new members, never update an existing one); `XX` (only update members that already exist). | +| `CH` | No | No | Count changed members rather than only new members. | +| ` ` | Yes | Yes | Longitude, latitude, and the member they belong to. Repeat to add several members. | + +## Important points + +* `NX` and `XX` are mutually exclusive. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.geoadd("my-key", { + longitude: 29.0, + latitude: 41.0, + member: "member", +}); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.geoadd("my-key", (29.0, 41.0, "member")) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.geoadd("my-key", "29.0", "41.0", "member"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.geoAdd("my-key", { longitude: 29, latitude: 41, member: "member" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.geoadd("my-key", (29.0, 41.0, "member")) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.GeoAdd(context.Background(), "my-key", &redis.GeoLocation{Longitude: 29.0, Latitude: 41.0, Name: "member"}).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.geoadd("my-key", 29.0, 41.0, "member"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("GEOADD"); + command.arg("my-key"); + command.arg("29.0"); + command.arg("41.0"); + command.arg("member"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# GEODIST +Source: https://upstash.com/docs/redis/commands/geo/geodist + +Use `GEODIST` to get distance between two members. + +## Syntax + +```redis +GEODIST [m | km | ft | mi] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | First member. | +| `` | Yes | No | Second member. | +| `(m \| km \| ft \| mi)` | No | No | Choose one form: `m`; `km`; `ft`; `mi`. | + +## Important points + +* The distance is always returned as a bulk string, in both RESP2 and RESP3. Client libraries commonly decode it to a language number. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Null bulk string or null array or Bulk string | +| RESP3 | Null or Bulk string | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.geodist("my-key", "member1", "member2"); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.geodist("my-key", "member1", "member2") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.geodist("my-key", "member1", "member2"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.geoDist("my-key", "member1", "member2"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.geodist("my-key", "member1", "member2") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.GeoDist(context.Background(), "my-key", "member1", "member2", "m").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.geodist("my-key", "member1", "member2"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("GEODIST"); + command.arg("my-key"); + command.arg("member1"); + command.arg("member2"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# GEOHASH +Source: https://upstash.com/docs/redis/commands/geo/geohash + +Use `GEOHASH` to get geohash strings for members. + +## Syntax + +```redis +GEOHASH [ [ ...]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | No | Yes | Member name. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string geohashes or null values | +| RESP3 | Array of bulk-string geohashes or null values | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.geohash("my-key", "member"); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.geohash("my-key", "member") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.geohash("my-key", "member"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.geoHash("my-key", "member"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.geohash("my-key", "member") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.GeoHash(context.Background(), "my-key", "member").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.geohash("my-key", "member"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("GEOHASH"); + command.arg("my-key"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# GEOPOS +Source: https://upstash.com/docs/redis/commands/geo/geopos + +Use `GEOPOS` to get coordinates of members. + +## Syntax + +```redis +GEOPOS [ [ ...]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | No | Yes | Member name. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of coordinate-pair arrays or null values | +| RESP3 | Array of coordinate-pair arrays or null values | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.geopos("my-key", "member"); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.geopos("my-key", "member") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.geopos("my-key", "member"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.geoPos("my-key", "member"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.geopos("my-key", "member") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.GeoPos(context.Background(), "my-key", "member").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.geopos("my-key", "member"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("GEOPOS"); + command.arg("my-key"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# GEORADIUS +Source: https://upstash.com/docs/redis/commands/geo/georadius + +Use `GEORADIUS` to query members within radius. + +## Syntax + +```redis +GEORADIUS (m | km | ft | mi) [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT [ANY]] [ASC | DESC] [STORE | STOREDIST ] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Longitude in degrees, from -180 to 180. | +| `` | Yes | No | Latitude in degrees, from -85.05112878 to 85.05112878. | +| `` | Yes | No | Search radius, in the unit given after it. | +| `(m \| km \| ft \| mi)` | Yes | No | Choose one form: `m`; `km`; `ft`; `mi`. | +| `WITHCOORD` | No | No | Also return the longitude and latitude of each match. | +| `WITHDIST` | No | No | Also return the distance from the center, in the requested unit. | +| `WITHHASH` | No | No | Also return the raw 52-bit geohash score of each match. | +| `COUNT [ANY]` | No | No | Return at most `` matches. `ANY` returns as soon as enough matches are found, instead of sorting every match first. | +| `(ASC \| DESC)` | No | No | Choose one form: `ASC`; `DESC`. | +| `(STORE \| STOREDIST )` | No | No | Choose one form: `STORE`; `STOREDIST`. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string members or member-detail arrays, or Integer when storing | +| RESP3 | Array of bulk-string members or member-detail arrays, or Integer when storing | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.georadius("my-key", 29.0, 41.0, 1.5, "M") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.georadius("my-key", "29.0", "41.0", "1.5", "m"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.geoRadius("my-key", { longitude: 29, latitude: 41 }, 1.5, "m"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.georadius("my-key", 29.0, 41.0, 1.5, "m") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.GeoRadius(context.Background(), "my-key", 29.0, 41.0, &redis.GeoRadiusQuery{Radius: 1.5, Unit: "m"}).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.georadius("my-key", 29.0, 41.0, 1.5, redis.clients.jedis.args.GeoUnit.M); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("GEORADIUS"); + command.arg("my-key"); + command.arg("29.0"); + command.arg("41.0"); + command.arg("1.5"); + command.arg("m"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# GEORADIUS_RO +Source: https://upstash.com/docs/redis/commands/geo/georadius-ro + +Use `GEORADIUS_RO` to find members within a radius of a point. It is the read-only form of `GEORADIUS`. + +## Syntax + +```redis +GEORADIUS_RO (m | km | ft | mi) [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT [ANY]] [ASC | DESC] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Longitude in degrees, from -180 to 180. | +| `` | Yes | No | Latitude in degrees, from -85.05112878 to 85.05112878. | +| `` | Yes | No | Search radius, in the unit given after it. | +| `(m \| km \| ft \| mi)` | Yes | No | Choose one form: `m`; `km`; `ft`; `mi`. | +| `WITHCOORD` | No | No | Also return the longitude and latitude of each match. | +| `WITHDIST` | No | No | Also return the distance from the center, in the requested unit. | +| `WITHHASH` | No | No | Also return the raw 52-bit geohash score of each match. | +| `COUNT [ANY]` | No | No | Return at most `` matches. `ANY` returns as soon as enough matches are found, instead of sorting every match first. | +| `(ASC \| DESC)` | No | No | Choose one form: `ASC`; `DESC`. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string members or member-detail arrays | +| RESP3 | Array of bulk-string members or member-detail arrays | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.georadius_ro("my-key", 29.0, 41.0, 1.5, "M") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.georadius_ro("my-key", "29.0", "41.0", "1.5", "m"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.geoRadiusRo("my-key", { longitude: 29, latitude: 41 }, 1.5, "m"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.execute_command("GEORADIUS_RO", "my-key", "29.0", "41.0", "1.5", "m") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.GeoRadius(context.Background(), "my-key", 29.0, 41.0, &redis.GeoRadiusQuery{Radius: 1.5, Unit: "m"}).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.georadiusReadonly("my-key", 29.0, 41.0, 1.5, redis.clients.jedis.args.GeoUnit.M); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("GEORADIUS_RO"); + command.arg("my-key"); + command.arg("29.0"); + command.arg("41.0"); + command.arg("1.5"); + command.arg("m"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# GEORADIUSBYMEMBER +Source: https://upstash.com/docs/redis/commands/geo/georadiusbymember + +Use `GEORADIUSBYMEMBER` to radius query centered on member. + +## Syntax + +```redis +GEORADIUSBYMEMBER (m | km | ft | mi) [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT [ANY]] [ASC | DESC] [STORE | STOREDIST ] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Member name. | +| `` | Yes | No | Search radius, in the unit given after it. | +| `(m \| km \| ft \| mi)` | Yes | No | Choose one form: `m`; `km`; `ft`; `mi`. | +| `WITHCOORD` | No | No | Also return the longitude and latitude of each match. | +| `WITHDIST` | No | No | Also return the distance from the center, in the requested unit. | +| `WITHHASH` | No | No | Also return the raw 52-bit geohash score of each match. | +| `COUNT [ANY]` | No | No | Return at most `` matches. `ANY` returns as soon as enough matches are found, instead of sorting every match first. | +| `(ASC \| DESC)` | No | No | Choose one form: `ASC`; `DESC`. | +| `(STORE \| STOREDIST )` | No | No | Choose one form: `STORE`; `STOREDIST`. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string members or member-detail arrays, or Integer when storing | +| RESP3 | Array of bulk-string members or member-detail arrays, or Integer when storing | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.georadiusbymember("my-key", "member", 1.5, "M") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.georadiusbymember("my-key", "member", "1.5", "m"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.geoRadiusByMember("my-key", "member", 1.5, "m"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.georadiusbymember("my-key", "member", 1.5, "m") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.GeoRadiusByMember(context.Background(), "my-key", "member", &redis.GeoRadiusQuery{Radius: 1.5, Unit: "m"}).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.georadiusByMember("my-key", "member", 1.5, redis.clients.jedis.args.GeoUnit.M); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("GEORADIUSBYMEMBER"); + command.arg("my-key"); + command.arg("member"); + command.arg("1.5"); + command.arg("m"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# GEORADIUSBYMEMBER_RO +Source: https://upstash.com/docs/redis/commands/geo/georadiusbymember-ro + +Use `GEORADIUSBYMEMBER_RO` to find members within a radius of another member. It is the read-only form of `GEORADIUSBYMEMBER`. + +## Syntax + +```redis +GEORADIUSBYMEMBER_RO (m | km | ft | mi) [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT [ANY]] [ASC | DESC] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Member name. | +| `` | Yes | No | Search radius, in the unit given after it. | +| `(m \| km \| ft \| mi)` | Yes | No | Choose one form: `m`; `km`; `ft`; `mi`. | +| `WITHCOORD` | No | No | Also return the longitude and latitude of each match. | +| `WITHDIST` | No | No | Also return the distance from the center, in the requested unit. | +| `WITHHASH` | No | No | Also return the raw 52-bit geohash score of each match. | +| `COUNT [ANY]` | No | No | Return at most `` matches. `ANY` returns as soon as enough matches are found, instead of sorting every match first. | +| `(ASC \| DESC)` | No | No | Choose one form: `ASC`; `DESC`. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string members or member-detail arrays | +| RESP3 | Array of bulk-string members or member-detail arrays | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.georadiusbymember_ro("my-key", "member", 1.5, "M") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.georadiusbymember_ro("my-key", "member", "1.5", "m"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.geoRadiusByMemberRo("my-key", "member", 1.5, "m"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.execute_command("GEORADIUSBYMEMBER_RO", "my-key", "member", "1.5", "m") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.GeoRadiusByMember(context.Background(), "my-key", "member", &redis.GeoRadiusQuery{Radius: 1.5, Unit: "m"}).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.georadiusByMemberReadonly("my-key", "member", 1.5, redis.clients.jedis.args.GeoUnit.M); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("GEORADIUSBYMEMBER_RO"); + command.arg("my-key"); + command.arg("member"); + command.arg("1.5"); + command.arg("m"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# GEOSEARCH +Source: https://upstash.com/docs/redis/commands/geo/geosearch + +Use `GEOSEARCH` to search for members in an area. + +## Syntax + +```redis +GEOSEARCH (FROMMEMBER | FROMLONLAT ) (BYRADIUS (m | km | ft | mi) | BYBOX (m | km | ft | mi)) [ASC | DESC] [COUNT [ANY]] [WITHCOORD] [WITHDIST] [WITHHASH] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `(FROMMEMBER \| FROMLONLAT )` | Yes | No | Choose one form: `FROMMEMBER`; `FROMLONLAT`. | +| `(BYRADIUS (m \| km \| ft \| mi) \| BYBOX (m \| km \| ft \| mi))` | Yes | No | Choose one form: `BYRADIUS`; `m`; `km`; `ft`; `mi`; `BYBOX`; `m`; `km`; `ft`; `mi`. | +| `(ASC \| DESC)` | No | No | Choose one form: `ASC`; `DESC`. | +| `COUNT [ANY]` | No | No | Return at most `` matches. `ANY` returns as soon as enough matches are found, instead of sorting every match first. | +| `WITHCOORD` | No | No | Also return the longitude and latitude of each match. | +| `WITHDIST` | No | No | Also return the distance from the center, in the requested unit. | +| `WITHHASH` | No | No | Also return the raw 52-bit geohash score of each match. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string members or member-detail arrays | +| RESP3 | Array of bulk-string members or member-detail arrays | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.geosearch( + "my-key", + { type: "FROMMEMBER", member: "member" }, + { type: "BYRADIUS", radius: 1.5, radiusType: "M" }, + "ASC", +); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.geosearch("my-key", member="member", radius=1.5, unit="M") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.geosearch("my-key", "FROMMEMBER", "member", "BYRADIUS", "1.5", "m"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.geoSearch("my-key", "member", { radius: 1.5, unit: "m" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.geosearch("my-key", member="member", radius=1.5, unit="m") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.GeoSearch(context.Background(), "my-key", &redis.GeoSearchQuery{Member: "member", Radius: 1.5, RadiusUnit: "m"}).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.geosearch("my-key", "member", 1.5, redis.clients.jedis.args.GeoUnit.M); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("GEOSEARCH"); + command.arg("my-key"); + command.arg("member"); + command.arg("1.5"); + command.arg("m"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# GEOSEARCHSTORE +Source: https://upstash.com/docs/redis/commands/geo/geosearchstore + +Use `GEOSEARCHSTORE` to store geosearch results. + +## Syntax + +```redis +GEOSEARCHSTORE (FROMMEMBER | FROMLONLAT ) (BYRADIUS (m | km | ft | mi) | BYBOX (m | km | ft | mi)) [ASC | DESC] [COUNT [ANY]] [STOREDIST] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key used as destination. | +| `` | Yes | No | Redis key used as source. | +| `(FROMMEMBER \| FROMLONLAT )` | Yes | No | Choose one form: `FROMMEMBER`; `FROMLONLAT`. | +| `(BYRADIUS (m \| km \| ft \| mi) \| BYBOX (m \| km \| ft \| mi))` | Yes | No | Choose one form: `BYRADIUS`; `m`; `km`; `ft`; `mi`; `BYBOX`; `m`; `km`; `ft`; `mi`. | +| `(ASC \| DESC)` | No | No | Choose one form: `ASC`; `DESC`. | +| `COUNT [ANY]` | No | No | Return at most `` matches. `ANY` returns as soon as enough matches are found, instead of sorting every match first. | +| `STOREDIST` | No | No | Store each match's distance from the center instead of its geohash score. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.geosearchstore( + "destination-key", + "source-key", + { type: "FROMMEMBER", member: "member" }, + { type: "BYRADIUS", radius: 1.5, radiusType: "M" }, + "ASC", +); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.geosearchstore("destination-key", "source-key", member="member", radius=1.5, unit="M") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.geosearchstore("destination-key", "source-key", "FROMMEMBER", "member", "BYRADIUS", "1.5", "m"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.geoSearchStore("destination-key", "source-key", "member", { radius: 1.5, unit: "m" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.geosearchstore("destination-key", "source-key", member="member", radius=1.5, unit="m") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.GeoSearchStore(context.Background(), "source-key", "destination-key", &redis.GeoSearchStoreQuery{GeoSearchQuery: redis.GeoSearchQuery{Member: "member", Radius: 1.5, RadiusUnit: "m"}}).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.geosearchStore("destination-key", "source-key", "member", 1.5, redis.clients.jedis.args.GeoUnit.M); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("GEOSEARCHSTORE"); + command.arg("destination-key"); + command.arg("source-key"); + command.arg("member"); + command.arg("1.5"); + command.arg("m"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# Geo commands +Source: https://upstash.com/docs/redis/commands/geo/overview + + +Add geospatial items +Get distance between two members +Get geohash strings for members +Get coordinates of members +Query members within radius +Read-only radius query +Radius query centered on member +Read-only radius query by member +Search for members in an area +Store geosearch results + + +# HDEL +Source: https://upstash.com/docs/redis/commands/hash/hdel + +Use `HDEL` to delete one or more hash fields. + +## Syntax + +```redis +HDEL [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | Yes | Hash field name. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hdel(key, 'field1', 'field2'); +// returns 5 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hdel("my-key", "field") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hdel("my-key", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hDel("my-key", "field"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hdel("my-key", "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HDel(context.Background(), "my-key", "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hdel("my-key", "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hdel("my-key", "field")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HEXISTS +Source: https://upstash.com/docs/redis/commands/hash/hexists + +Use `HEXISTS` to check if a hash field exists. + +## Syntax + +```redis +HEXISTS +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Hash field name. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: `1` if the field exists, `0` otherwise | +| RESP3 | Integer: `1` if the field exists, `0` otherwise | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("key", "field", "value"); +const exists = await redis.hexists("key", "field"); + +console.log(exists); // 1 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hexists("my-key", "field") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hexists("my-key", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hExists("my-key", "field"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hexists("my-key", "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HExists(context.Background(), "my-key", "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hexists("my-key", "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hexists("my-key", "field")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HEXPIRE +Source: https://upstash.com/docs/redis/commands/hash/hexpire + +Use `HEXPIRE` to set field TTL in seconds. + +## Syntax + +```redis +HEXPIRE [NX | XX | GT | LT] FIELDS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Lifetime in seconds. | +| `(NX \| XX \| GT \| LT)` | No | No | Choose one form: `NX` (only when the field has no expiration); `XX` (only when the field already has one); `GT` (only when the new expiration is later than the current one); `LT` (only when it is earlier). | +| `FIELDS [ ...]` | Yes | No | Fields to target. Give the field count first, then that many field names. | + +## Important points + +* `NX` cannot be combined with `XX`, `GT`, or `LT`, and `GT` and `LT` cannot be used together. +* A field with no expiration counts as an infinite one, so `GT` never sets an expiration on such a field and `LT` always does. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer status codes, one per field | +| RESP3 | Array of integer status codes, one per field | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("my-key", "my-field", "my-value"); +const expirationSet = await redis.hexpire("my-key", "my-field", 1); + +console.log(expirationSet); // 1 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hexpire("my-key", "field", 1000) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hexpire("my-key", "1000", "FIELDS", "1", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hExpire("my-key", "field", 1000); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hexpire("my-key", 1000, "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HExpire(context.Background(), "my-key", 1000*time.Second, "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hexpire("my-key", 1000, "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hexpire("my-key", 1000, redis::ExpireOption::NONE, &["field"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HEXPIREAT +Source: https://upstash.com/docs/redis/commands/hash/hexpireat + +Use `HEXPIREAT` to set field expiry as timestamp. + +## Syntax + +```redis +HEXPIREAT [NX | XX | GT | LT] FIELDS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Expiration time as a Unix timestamp in seconds. | +| `(NX \| XX \| GT \| LT)` | No | No | Choose one form: `NX` (only when the field has no expiration); `XX` (only when the field already has one); `GT` (only when the new expiration is later than the current one); `LT` (only when it is earlier). | +| `FIELDS [ ...]` | Yes | No | Fields to target. Give the field count first, then that many field names. | + +## Important points + +* `NX` cannot be combined with `XX`, `GT`, or `LT`, and `GT` and `LT` cannot be used together. +* A field with no expiration counts as an infinite one, so `GT` never sets an expiration on such a field and `LT` always does. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer status codes, one per field | +| RESP3 | Array of integer status codes, one per field | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("my-key", "my-field", "my-value"); +const expirationSet = await redis.hexpireat("my-key", "my-field", Math.floor(Date.now() / 1000) + 10); + +console.log(expirationSet); // [1] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hexpireat("my-key", "field", 1735689600) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hexpireat("my-key", "1735689600", "FIELDS", "1", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hExpireAt("my-key", "field", 1735689600); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hexpireat("my-key", 1735689600, "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HExpireAt(context.Background(), "my-key", time.Unix(1735689600, 0), "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hexpireAt("my-key", 1735689600, "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hexpire_at("my-key", 1735689600, redis::ExpireOption::NONE, &["field"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HEXPIRETIME +Source: https://upstash.com/docs/redis/commands/hash/hexpiretime + +Use `HEXPIRETIME` to get field expiry as timestamp. + +## Syntax + +```redis +HEXPIRETIME FIELDS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `FIELDS [ ...]` | Yes | No | Fields to target. Give the field count first, then that many field names. | + +## Important points + +* Negative integer replies are sentinel values, not durations or timestamps; see the response description for missing or persistent data. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of expiration timestamps or negative integer status codes, one per field | +| RESP3 | Array of expiration timestamps or negative integer status codes, one per field | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("my-key", "my-field", "my-value"); +await redis.hexpireat("my-key", "my-field", Math.floor(Date.now() / 1000) + 10); +const expireTime = await redis.hexpiretime("my-key", "my-field"); + +console.log(expireTime); // e.g., [1697059200] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hexpiretime("my-key", "field") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hexpiretime("my-key", "FIELDS", "1", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hExpireTime("my-key", "field"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hexpiretime("my-key", "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HExpireTime(context.Background(), "my-key", "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hexpireTime("my-key", "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hexpire_time("my-key", &["field"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HGET +Source: https://upstash.com/docs/redis/commands/hash/hget + +Use `HGET` to get the value of a hash field. + +## Syntax + +```redis +HGET +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Hash field name. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string or Null bulk string or null array | +| RESP3 | Bulk string or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("key", {field: "value"}); +const field = await redis.hget("key", "field"); +console.log(field); // "value" +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hget("my-key", "field") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hget("my-key", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hGet("my-key", "field"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hget("my-key", "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HGet(context.Background(), "my-key", "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hget("my-key", "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hget("my-key", "field")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HGETALL +Source: https://upstash.com/docs/redis/commands/hash/hgetall + +Use `HGETALL` to get all fields and values. + +## Syntax + +```redis +HGETALL +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | + +## Important points + +* Pair-based results may be flattened into one alternating array in RESP2 while RESP3 preserves nested pairs or a map. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Flat array of alternating keys and values | +| RESP3 | Map | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("key", { + field1: "value1", + field2: "value2", + }); +const hash = await redis.hgetall("key"); +console.log(hash); // { field1: "value1", field2: "value2" } +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hgetall("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hgetall("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hGetAll("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hgetall("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HGetAll(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hgetAll("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hgetall("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HGETDEL +Source: https://upstash.com/docs/redis/commands/hash/hgetdel + +Use `HGETDEL` to get and delete hash fields. + +## Syntax + +```redis +HGETDEL FIELDS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `FIELDS [ ...]` | Yes | No | Fields to target. Give the field count first, then that many field names. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string values or null values, one per field | +| RESP3 | Array of bulk-string values or null values, one per field | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +// Set some hash fields +await redis.hset("user:123", { name: "John", age: "30", email: "john@example.com" }); + +// Get and delete specific fields +const result = await redis.hgetdel("user:123", "name", "email"); +console.log(result); // { name: "John", email: "john@example.com" } + +// Verify fields were deleted +const name = await redis.hget("user:123", "name"); +console.log(name); // null +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hgetdel("my-key", "field") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hgetdel("my-key", "FIELDS", "1", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hGetDel("my-key", "field"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hgetdel("my-key", "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HGetDel(context.Background(), "my-key", "1", "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hgetdel("my-key", "1", "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hget_del("my-key", &["field"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HGETEX +Source: https://upstash.com/docs/redis/commands/hash/hgetex + +Use `HGETEX` to get fields and set their expiry. + +## Syntax + +```redis +HGETEX [EX | PX | EXAT | PXAT | PERSIST] FIELDS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `(EX \| PX \| EXAT \| PXAT \| PERSIST)` | No | No | Choose one form: `EX` (set a lifetime in seconds); `PX` (set a lifetime in milliseconds); `EXAT` (expire at a Unix timestamp in seconds); `PXAT` (expire at a Unix timestamp in milliseconds); `PERSIST`. | +| `FIELDS [ ...]` | Yes | No | Fields to target. Give the field count first, then that many field names. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string values or null values, one per field | +| RESP3 | Array of bulk-string values or null values, one per field | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("user:123", { name: "John", email: "john@example.com" }); + +// Get fields and set expiration to 60 seconds +const result = await redis.hgetex("user:123", { ex: 60 }, "name", "email"); +console.log(result); // { name: "John", email: "john@example.com" } +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hgetex("my-key", "field") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hgetex("my-key", "FIELDS", "1", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hGetEx("my-key", "field"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hgetex("my-key", "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HGetEX(context.Background(), "my-key", "1", "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hgetex("my-key", redis.clients.jedis.params.HGetExParams.hGetExParams(), "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hget_ex("my-key", &["field"], redis::Expiry::PERSIST)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HINCRBY +Source: https://upstash.com/docs/redis/commands/hash/hincrby + +Use `HINCRBY` to increment integer value of a field. + +## Syntax + +```redis +HINCRBY +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Hash field name. | +| `` | Yes | No | Integer amount to add to the field. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("key", { + field: 20, + }); +const after = await redis.hincrby("key", "field", 2); +console.log(after); // 22 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hincrby("my-key", "field", 1) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hincrby("my-key", "field", "1"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hIncrBy("my-key", "field", 1); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hincrby("my-key", "field", 1) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HIncrBy(context.Background(), "my-key", "field", 1).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hincrBy("my-key", "field", 1); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hincr("my-key", "field", 1)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HINCRBYFLOAT +Source: https://upstash.com/docs/redis/commands/hash/hincrbyfloat + +Use `HINCRBYFLOAT` to increment float value of a field. + +## Syntax + +```redis +HINCRBYFLOAT +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Hash field name. | +| `` | Yes | No | Amount to add to the field; may be a floating-point number. | + +## Important points + +* The value is always returned as a bulk string, in both RESP2 and RESP3. Client libraries commonly decode it to a language number. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string | +| RESP3 | Bulk string | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("key", { + field: 20, + }); +const after = await redis.hincrby("key", "field", 2.5); +console.log(after); // 22.5 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hincrbyfloat("my-key", "field", 1.5) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hincrbyfloat("my-key", "field", "1.5"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hIncrByFloat("my-key", "field", 1.5); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hincrbyfloat("my-key", "field", 1.5) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HIncrByFloat(context.Background(), "my-key", "field", 1.5).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hincrByFloat("my-key", "field", 1.5); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hincr("my-key", "field", 1.5)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HKEYS +Source: https://upstash.com/docs/redis/commands/hash/hkeys + +Use `HKEYS` to get all fields in a hash. + +## Syntax + +```redis +HKEYS +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string fields | +| RESP3 | Array of bulk-string fields | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("key", { + id: 1, + username: "chronark", + }); +const fields = await redis.hkeys("key"); +console.log(fields); // ["id", "username"] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hkeys("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hkeys("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hKeys("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hkeys("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HKeys(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hkeys("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hkeys("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HLEN +Source: https://upstash.com/docs/redis/commands/hash/hlen + +Use `HLEN` to get number of fields in a hash. + +## Syntax + +```redis +HLEN +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("key", { + id: 1, + username: "chronark", + }); +const fields = await redis.hlen("key"); +console.log(fields); // 2 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hlen("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hlen("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hLen("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hlen("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HLen(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hlen("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hlen("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HMGET +Source: https://upstash.com/docs/redis/commands/hash/hmget + +Use `HMGET` to get values of multiple fields. + +## Syntax + +```redis +HMGET [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | Yes | Hash field name. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string values or null values, one per field | +| RESP3 | Array of bulk-string values or null values, one per field | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("key", { + id: 1, + username: "chronark", + name: "andreas" + }); +const fields = await redis.hmget("key", "username", "name"); +console.log(fields); // { username: "chronark", name: "andreas" } +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hmget("my-key", "field") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hmget("my-key", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hmGet("my-key", "field"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hmget("my-key", ["field"]) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HMGet(context.Background(), "my-key", "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hmget("my-key", "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hmget("my-key", &["field"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HMSET +Source: https://upstash.com/docs/redis/commands/hash/hmset + +Use `HMSET` to set multiple hash fields. + +## Syntax + +```redis +HMSET [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| ` ` | Yes | Yes | Field and the value to store in it. Repeat to set several fields in one call. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.hmset("my-key", { field: "value" }); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hmset("my-key", {"field": "value"}) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hmset("my-key", "field", "value"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hSet("my-key", { field: "value" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hset("my-key", mapping={"field": "value"}) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HMSet(context.Background(), "my-key", "field", "value").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hmset("my-key", java.util.Map.of("field", "value")); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hset_multiple("my-key", &[("field", "value")])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HPERSIST +Source: https://upstash.com/docs/redis/commands/hash/hpersist + +Use `HPERSIST` to remove field expiration. + +## Syntax + +```redis +HPERSIST FIELDS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `FIELDS [ ...]` | Yes | No | Fields to target. Give the field count first, then that many field names. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer status codes, one per field | +| RESP3 | Array of integer status codes, one per field | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("my-key", "my-field", "my-value"); +await redis.hpexpire("my-key", "my-field", 1000); + +const expirationRemoved = await redis.hpersist("my-key", "my-field"); + +console.log(expirationRemoved); // [1] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hpersist("my-key", "field") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hpersist("my-key", "FIELDS", "1", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hPersist("my-key", "field"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hpersist("my-key", "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HPersist(context.Background(), "my-key", "1", "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hpersist("my-key", "1", "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hpersist("my-key", &["field"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HPEXPIRE +Source: https://upstash.com/docs/redis/commands/hash/hpexpire + +Use `HPEXPIRE` to set field TTL in milliseconds. + +## Syntax + +```redis +HPEXPIRE [NX | XX | GT | LT] FIELDS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Lifetime in milliseconds. | +| `(NX \| XX \| GT \| LT)` | No | No | Choose one form: `NX` (only when the field has no expiration); `XX` (only when the field already has one); `GT` (only when the new expiration is later than the current one); `LT` (only when it is earlier). | +| `FIELDS [ ...]` | Yes | No | Fields to target. Give the field count first, then that many field names. | + +## Important points + +* `NX` cannot be combined with `XX`, `GT`, or `LT`, and `GT` and `LT` cannot be used together. +* A field with no expiration counts as an infinite one, so `GT` never sets an expiration on such a field and `LT` always does. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer status codes, one per field | +| RESP3 | Array of integer status codes, one per field | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("my-key", "my-field", "my-value"); +const expirationSet = await redis.hpexpire("my-key", "my-field", 1000); + +console.log(expirationSet); // [1] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hpexpire("my-key", "field", 1000) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hpexpire("my-key", "1000", "FIELDS", "1", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hpExpire("my-key", "field", 1000); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hpexpire("my-key", 1000, "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HPExpire(context.Background(), "my-key", time.Second, "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hpexpire("my-key", 1000, "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hpexpire("my-key", 1000, redis::ExpireOption::NONE, &["field"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HPEXPIREAT +Source: https://upstash.com/docs/redis/commands/hash/hpexpireat + +Use `HPEXPIREAT` to set field expiry as ms timestamp. + +## Syntax + +```redis +HPEXPIREAT [NX | XX | GT | LT] FIELDS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Expiration time as a Unix timestamp in milliseconds. | +| `(NX \| XX \| GT \| LT)` | No | No | Choose one form: `NX` (only when the field has no expiration); `XX` (only when the field already has one); `GT` (only when the new expiration is later than the current one); `LT` (only when it is earlier). | +| `FIELDS [ ...]` | Yes | No | Fields to target. Give the field count first, then that many field names. | + +## Important points + +* `NX` cannot be combined with `XX`, `GT`, or `LT`, and `GT` and `LT` cannot be used together. +* A field with no expiration counts as an infinite one, so `GT` never sets an expiration on such a field and `LT` always does. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer status codes, one per field | +| RESP3 | Array of integer status codes, one per field | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("my-key", "my-field", "my-value"); +const expirationSet = await redis.hpexpireat("my-key", "my-field", Date.now() + 1000); + +console.log(expirationSet); // [1] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hpexpireat("my-key", "field", 1735689600) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hpexpireat("my-key", "1735689600", "FIELDS", "1", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hpExpireAt("my-key", "field", 1735689600); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hpexpireat("my-key", 1735689600, "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HPExpireAt(context.Background(), "my-key", time.UnixMilli(1735689600), "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hpexpireAt("my-key", 1735689600, "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hpexpire_at("my-key", 1735689600, redis::ExpireOption::NONE, &["field"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HPEXPIRETIME +Source: https://upstash.com/docs/redis/commands/hash/hpexpiretime + +Use `HPEXPIRETIME` to get field expiry as ms timestamp. + +## Syntax + +```redis +HPEXPIRETIME FIELDS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `FIELDS [ ...]` | Yes | No | Fields to target. Give the field count first, then that many field names. | + +## Important points + +* Negative integer replies are sentinel values, not durations or timestamps; see the response description for missing or persistent data. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of expiration timestamps or negative integer status codes, one per field | +| RESP3 | Array of expiration timestamps or negative integer status codes, one per field | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("my-key", "my-field", "my-value"); +await redis.hpexpireat("my-key", "my-field", Date.now() + 1000); +const expireTime = await redis.hpexpiretime("my-key", "my-field"); + +console.log(expireTime); // e.g., 1697059200000 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hpexpiretime("my-key", "field") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hpexpiretime("my-key", "FIELDS", "1", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hpExpireTime("my-key", "field"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hpexpiretime("my-key", "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HPExpireTime(context.Background(), "my-key", "1", "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hpexpireTime("my-key", "1", "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hpexpire_time("my-key", &["field"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HPTTL +Source: https://upstash.com/docs/redis/commands/hash/hpttl + +Use `HPTTL` to get field TTL in milliseconds. + +## Syntax + +```redis +HPTTL FIELDS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `FIELDS [ ...]` | Yes | No | Fields to target. Give the field count first, then that many field names. | + +## Important points + +* Negative integer replies are sentinel values, not durations or timestamps; see the response description for missing or persistent data. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of TTL values or negative integer status codes, one per field | +| RESP3 | Array of TTL values or negative integer status codes, one per field | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("my-key", "my-field", "my-value"); +await redis.hpexpire("my-key", "my-field", 1000); +const ttl = await redis.hpttl("my-key", "my-field"); + +console.log(ttl); // e.g., [950] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hpttl("my-key", "field") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hpttl("my-key", "FIELDS", "1", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hpTTL("my-key", "field"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hpttl("my-key", "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HPTTL(context.Background(), "my-key", "1", "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hpttl("my-key", "1", "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hpttl("my-key", &["field"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HRANDFIELD +Source: https://upstash.com/docs/redis/commands/hash/hrandfield + +Use `HRANDFIELD` to get random fields from a hash. + +## Syntax + +```redis +HRANDFIELD [ [WITHVALUES]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| ` [WITHVALUES]` | No | No | Number of fields to return; a negative count may repeat fields. `WITHVALUES` also returns each field's value. | + +## Important points + +* Pair-based results may be flattened into one alternating array in RESP2 while RESP3 preserves nested pairs or a map. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Null bulk string or null array, Bulk string, array of fields, or flat field/value array | +| RESP3 | Null, Bulk string, array of fields, or array of field/value pairs | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("key", { + id: 1, + username: "chronark", + name: "andreas" + }); +const randomField = await redis.hrandfield("key"); +console.log(randomField); // one of "id", "username" or "name" +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hrandfield("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hrandfield("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hRandField("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hrandfield("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HRandField(context.Background(), "my-key", 1).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hrandfield("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("HRANDFIELD"); + command.arg("my-key"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HSCAN +Source: https://upstash.com/docs/redis/commands/hash/hscan + +Use `HSCAN` to incrementally iterate hash fields. + +## Syntax + +```redis +HSCAN [MATCH ] [COUNT ] [NOVALUES] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Cursor returned by the previous call; start at `0`. | +| `MATCH ` | No | No | Return only elements matching this glob-style pattern. | +| `COUNT ` | No | No | Hint for how much work each iteration should do. | +| `NOVALUES` | No | No | Return only field names, without their values. | + +## Important points + +* This operation can inspect a large part of the database. Prefer cursor-based scans where possible and avoid unbounded use on hot paths. +* The cursor is opaque. Start with `0` and continue until the server returns cursor `0`; a single iteration may return no elements. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Two-element array: cursor and flat field/value array, or field array with `NOVALUES` | +| RESP3 | Two-element array: cursor and flat field/value array, or field array with `NOVALUES` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("key", { + id: 1, + username: "chronark", + name: "andreas" + }); +const [newCursor, fields] = await redis.hscan("key", 0); +console.log(newCursor); // likely `0` since this is a very small hash +console.log(fields); // ["id", 1, "username", "chronark", "name", "andreas"] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hscan("my-key", 0) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hscan("my-key", "0"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hScan("my-key", "0"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hscan("my-key", 0) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, _, err := client.HScan(context.Background(), "my-key", 0, "*", 0).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hscan("my-key", "0"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("HSCAN"); + command.arg("my-key"); + command.arg("0"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HSET +Source: https://upstash.com/docs/redis/commands/hash/hset + +Use `HSET` to set hash field values. + +## Syntax + +```redis +HSET [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| ` ` | Yes | Yes | Field and the value to store in it. Repeat to set several fields in one call. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("key", { + id: 1, + username: "chronark", + name: "andreas" + }); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hset("my-key", "field", "value") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hset("my-key", "field", "value"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hSet("my-key", "field", "value"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hset("my-key", "field", "value") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HSet(context.Background(), "my-key", "field", "value").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hset("my-key", "field", "value"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hset("my-key", "field", "value")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HSETEX +Source: https://upstash.com/docs/redis/commands/hash/hsetex + +Use `HSETEX` to set fields with expiration. + +## Syntax + +```redis +HSETEX [FNX | FXX] [EX | PX | EXAT | PXAT | KEEPTTL] FIELDS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `(FNX \| FXX)` | No | No | Choose one form: `FNX`; `FXX`. | +| `(EX \| PX \| EXAT \| PXAT \| KEEPTTL)` | No | No | Choose one form: `EX` (set a lifetime in seconds); `PX` (set a lifetime in milliseconds); `EXAT` (expire at a Unix timestamp in seconds); `PXAT` (expire at a Unix timestamp in milliseconds); `KEEPTTL` (preserve the existing key lifetime). | +| `FIELDS [ ...]` | Yes | No | Field-value pairs to set. Give the pair count first, then that many field and value pairs. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: `1` if the fields were set, `0` otherwise | +| RESP3 | Integer: `1` if the fields were set, `0` otherwise | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +// Set fields with 1 hour expiration +await redis.hsetex("user:123", { expiration: { ex: 3600 } }, { + name: "John", + email: "john@example.com" +}); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hsetex("my-key", field="field", value="value") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hsetex("my-key", "FIELDS", "1", "field", "value"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hSetEx("my-key", { field: "value" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hsetex("my-key", mapping={"field": "value"}) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HSetEX(context.Background(), "my-key", "1", "field", "value").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hsetex("my-key", redis.clients.jedis.params.HSetExParams.hSetExParams(), "field", "value"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("HSETEX"); + command.arg("my-key"); + command.arg("FIELDS"); + command.arg("1"); + command.arg("field"); + command.arg("value"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HSETNX +Source: https://upstash.com/docs/redis/commands/hash/hsetnx + +Use `HSETNX` to set field only if it doesn't exist. + +## Syntax + +```redis +HSETNX +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Hash field name. | +| `` | Yes | No | Value to store in the field. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: `1` if the field was set, `0` if it already exists | +| RESP3 | Integer: `1` if the field was set, `0` if it already exists | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hsetnx("key", "id", 1) +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hsetnx("my-key", "field", "value") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hsetnx("my-key", "field", "value"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hSetNX("my-key", "field", "value"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hsetnx("my-key", "field", "value") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HSetNX(context.Background(), "my-key", "field", "value").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hsetnx("my-key", "field", "value"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hset_nx("my-key", "field", "value")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HSTRLEN +Source: https://upstash.com/docs/redis/commands/hash/hstrlen + +Use `HSTRLEN` to get length of a field's value. + +## Syntax + +```redis +HSTRLEN +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Hash field name. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const length = await redis.hstrlen("key", "field") +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hstrlen("my-key", "field") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hstrlen("my-key", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hStrLen("my-key", "field"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hstrlen("my-key", "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HStrLen(context.Background(), "my-key", "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hstrlen("my-key", "field"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("HSTRLEN"); + command.arg("my-key"); + command.arg("field"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HTTL +Source: https://upstash.com/docs/redis/commands/hash/httl + +Use `HTTL` to get field TTL in seconds. + +## Syntax + +```redis +HTTL FIELDS [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `FIELDS [ ...]` | Yes | No | Fields to target. Give the field count first, then that many field names. | + +## Important points + +* Negative integer replies are sentinel values, not durations or timestamps; see the response description for missing or persistent data. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of TTL values or negative integer status codes, one per field | +| RESP3 | Array of TTL values or negative integer status codes, one per field | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("my-key", "my-field", "my-value"); +await redis.hexpire("my-key", "my-field", 10); +const ttl = await redis.httl("my-key", "my-field"); + +console.log(ttl); // e.g., [9] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.httl("my-key", "field") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.httl("my-key", "FIELDS", "1", "field"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hTTL("my-key", "field"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.httl("my-key", "field") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HTTL(context.Background(), "my-key", "1", "field").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.httl("my-key", "1", "field"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.httl("my-key", &["field"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# HVALS +Source: https://upstash.com/docs/redis/commands/hash/hvals + +Use `HVALS` to get all values in a hash. + +## Syntax + +```redis +HVALS +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string values | +| RESP3 | Array of bulk-string values | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.hset("key", { + field1: "Hello", + field2: "World", +}) +const values = await redis.hvals("key") +console.log(values) // ["Hello", "World"] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.hvals("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.hvals("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.hVals("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.hvals("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.HVals(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.hvals("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.hvals("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# Hash commands +Source: https://upstash.com/docs/redis/commands/hash/overview + + +Delete one or more hash fields +Check if a hash field exists +Set field TTL in seconds +Set field expiry as timestamp +Get field expiry as timestamp +Get the value of a hash field +Get all fields and values +Get and delete hash fields +Get fields and set their expiry +Increment integer value of a field +Increment float value of a field +Get all fields in a hash +Get number of fields in a hash +Get values of multiple fields +Set multiple hash fields +Remove field expiration +Set field TTL in milliseconds +Set field expiry as ms timestamp +Get field expiry as ms timestamp +Get field TTL in milliseconds +Get random fields from a hash +Incrementally iterate hash fields +Set hash field values +Set fields with expiration +Set field only if it doesn't exist +Get length of a field's value +Get field TTL in seconds +Get all values in a hash + + +# HyperLogLog commands +Source: https://upstash.com/docs/redis/commands/hyperloglog/overview + + +Add elements to HyperLogLog +Get estimated cardinality +Merge multiple HyperLogLogs + + +# PFADD +Source: https://upstash.com/docs/redis/commands/hyperloglog/pfadd + +Use `PFADD` to add elements to HyperLogLog. + +## Syntax + +```redis +PFADD [ [ ...]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | No | Yes | Element to add to the HyperLogLog. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: `1` if at least one internal register was altered, `0` otherwise | +| RESP3 | Integer: `1` if at least one internal register was altered, `0` otherwise | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.pfadd("my-key", "element"); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.pfadd("my-key", "member") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.pfadd("my-key", "element"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.pfAdd("my-key", "element"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.pfadd("my-key", "member") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.PFAdd(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.pfadd("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.pfadd("my-key", &["member"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# PFCOUNT +Source: https://upstash.com/docs/redis/commands/hyperloglog/pfcount + +Use `PFCOUNT` to get estimated cardinality. + +## Syntax + +```redis +PFCOUNT [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | Yes | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.pfcount("my-key"); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.pfcount("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.pfcount("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.pfCount("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.pfcount("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.PFCount(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.pfcount("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.pfcount(&["my-key"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# PFMERGE +Source: https://upstash.com/docs/redis/commands/hyperloglog/pfmerge + +Use `PFMERGE` to merge multiple HyperLogLogs. + +## Syntax + +```redis +PFMERGE [ [ ...]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key used as destkey. | +| `` | No | Yes | Redis key used as sourcekey. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.pfmerge("destination-key", "source-key"); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.pfmerge("destination-key", "source-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.pfmerge("destination-key", "source-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.pfMerge("destination-key", "source-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.pfmerge("destination-key", "source-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.PFMerge(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.pfmerge("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.pfmerge("destination-key", &["source-key"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.ARRAPPEND +Source: https://upstash.com/docs/redis/commands/json/json-arrappend + +Use `JSON.ARRAPPEND` to append values to JSON array. + +## Syntax + +```redis +JSON.ARRAPPEND [value ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | Yes | No | Path selecting arrays. | +| `value` | Yes | Yes | Valid JSON value to append. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer lengths or null values, one per matched path | +| RESP3 | Array of integer lengths or null values, one per matched path | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.json.arrappend("key", "$.path.to.array", "a"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().arrappend("profile", "$.tags", "new") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.ARRAPPEND", "profile", "$.tags", "\"new\""); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.arrAppend("profile", "$.tags", "new"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().arrappend("profile", "$.tags", "new") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONArrAppend(context.Background(), "profile", "$.tags", "new").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonArrAppend("profile", new redis.clients.jedis.json.Path("$.tags"), "new"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_arr_append("profile", "$.tags", &"new")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.ARRINDEX +Source: https://upstash.com/docs/redis/commands/json/json-arrindex + +Use `JSON.ARRINDEX` to find index of value in array. + +## Syntax + +```redis +JSON.ARRINDEX [start [stop]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | Yes | No | Path selecting arrays. | +| `value` | Yes | No | Valid JSON value to locate. | +| `start` | No | No | Inclusive starting index. | +| `stop` | No | No | Exclusive ending index. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer indexes or null values, one per matched path | +| RESP3 | Array of integer indexes or null values, one per matched path | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const index = await redis.json.arrindex("key", "$.path.to.array", "a"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().arrindex("profile", "$.tags", "new") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.ARRINDEX", "profile", "$.tags", "\"new\""); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.arrIndex("profile", "$.tags", "new"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().arrindex("profile", "$.tags", "new") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONArrIndex(context.Background(), "profile", "$.tags", "new").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonArrIndex("profile", new redis.clients.jedis.json.Path("$.tags"), "new"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_arr_index("profile", "$.tags", &"new")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.ARRINSERT +Source: https://upstash.com/docs/redis/commands/json/json-arrinsert + +Use `JSON.ARRINSERT` to insert values into JSON array. + +## Syntax + +```redis +JSON.ARRINSERT [value ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | Yes | No | Path selecting arrays. | +| `index` | Yes | No | Insertion index; negative indexes count from the end. | +| `value` | Yes | Yes | Valid JSON value to insert. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer lengths or null values, one per matched path | +| RESP3 | Array of integer lengths or null values, one per matched path | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const length = await redis.json.arrinsert("key", "$.path.to.array", 2, "a", "b"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().arrinsert("profile", "$.tags", 0, "first") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.ARRINSERT", "profile", "$.tags", "0", "\"first\""); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.arrInsert("profile", "$.tags", 0, "first"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().arrinsert("profile", "$.tags", 0, "first") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONArrInsert(context.Background(), "profile", "$.tags", 0, "first").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonArrInsert("profile", new redis.clients.jedis.json.Path("$.tags"), 0, "first"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_arr_insert("profile", "$.tags", 0, &"first")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.ARRLEN +Source: https://upstash.com/docs/redis/commands/json/json-arrlen + +Use `JSON.ARRLEN` to get JSON array length. + +## Syntax + +```redis +JSON.ARRLEN [path] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | No | No | Path selecting arrays; defaults to the root. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer lengths or null values, one per matched path | +| RESP3 | Array of integer lengths or null values, one per matched path | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const length = await redis.json.arrlen("key", "$.path.to.array"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().arrlen("profile", "$.tags") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.ARRLEN", "profile", "$.tags"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.arrLen("profile", { path: "$.tags" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().arrlen("profile", "$.tags") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONArrLen(context.Background(), "profile", "$.tags").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonArrLen("profile", new redis.clients.jedis.json.Path("$.tags")); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_arr_len("profile", "$.tags")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.ARRPOP +Source: https://upstash.com/docs/redis/commands/json/json-arrpop + +Use `JSON.ARRPOP` to pop value from JSON array. + +## Syntax + +```redis +JSON.ARRPOP [path [index]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | No | No | Path selecting arrays; defaults to the root. | +| `index` | No | No | Element index; defaults to the last element. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string JSON values or null values, one per matched path | +| RESP3 | Array of bulk-string JSON values or null values, one per matched path | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const element = await redis.json.arrpop("key", "$.path.to.array"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().arrpop("profile", "$.tags", -1) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.ARRPOP", "profile", "$.tags", "-1"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.arrPop("profile", { path: "$.tags", index: -1 }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().arrpop("profile", "$.tags", -1) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONArrPop(context.Background(), "profile", "$.tags", -1).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonArrPop("profile", new redis.clients.jedis.json.Path("$.tags"), -1); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_arr_pop("profile", "$.tags", -1)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.ARRTRIM +Source: https://upstash.com/docs/redis/commands/json/json-arrtrim + +Use `JSON.ARRTRIM` to trim JSON array to range. + +## Syntax + +```redis +JSON.ARRTRIM +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | Yes | No | Path selecting arrays. | +| `start` | Yes | No | Inclusive first index to keep. | +| `stop` | Yes | No | Inclusive last index to keep. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer lengths or null values, one per matched path | +| RESP3 | Array of integer lengths or null values, one per matched path | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const length = await redis.json.arrtrim("key", "$.path.to.array", 2, 10); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().arrtrim("profile", "$.tags", 0, 9) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.ARRTRIM", "profile", "$.tags", "0", "9"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.arrTrim("profile", "$.tags", 0, 9); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().arrtrim("profile", "$.tags", 0, 9) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONArrTrimWithArgs(context.Background(), "profile", "$.tags", &redis.JSONArrTrimArgs{Start: 0, Stop: func() *int { stop := 9; return &stop }()}).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonArrTrim("profile", new redis.clients.jedis.json.Path("$.tags"), 0, 9); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_arr_trim("profile", "$.tags", 0, 9)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.CLEAR +Source: https://upstash.com/docs/redis/commands/json/json-clear + +Use `JSON.CLEAR` to clear JSON values. + +## Syntax + +```redis +JSON.CLEAR [path] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | No | No | Path to containers or numbers; defaults to the root. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.json.clear("key"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().clear("profile", "$.stats") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.CLEAR", "profile", "$.stats"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.clear("profile", { path: "$.stats" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().clear("profile", "$.stats") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONClear(context.Background(), "profile", "$.stats").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonClear("profile", new redis.clients.jedis.json.Path("$.stats")); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_clear("profile", "$.stats")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.DEBUG +Source: https://upstash.com/docs/redis/commands/json/json-debug + +Use `JSON.DEBUG` to inspect JSON memory usage. + +## Syntax + +```redis +JSON.DEBUG MEMORY [path] +JSON.DEBUG HELP +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `MEMORY` | One form | No | Report the approximate memory used by the JSON value selected by key and optional path. | +| `key` | For MEMORY | No | JSON document key. | +| `path` | No | No | JSONPath to inspect; defaults to the root. | +| `HELP` | One form | No | Return the supported JSON.DEBUG forms. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer, array of integers, or array of help strings | +| RESP3 | Integer, array of integers, or array of help strings | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.DEBUG", "MEMORY", "profile", "$.stats"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.debugMemory("profile", { path: "$.stats" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().debug("MEMORY", "profile", "$.stats") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONDebugMemory(context.Background(), "profile", "$.stats").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonDebugMemory("profile", new redis.clients.jedis.json.Path("$.stats")); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("JSON.DEBUG"); + command.arg("MEMORY"); + command.arg("profile"); + command.arg("$.stats"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.DEL +Source: https://upstash.com/docs/redis/commands/json/json-del + +Use `JSON.DEL` to delete JSON values. + +## Syntax + +```redis +JSON.DEL [path] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | No | No | Path to delete; omitting it deletes the whole key. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.json.del("key", "$.path.to.value"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().delete("profile", "$.temporary") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.DEL", "profile", "$.temporary"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.del("profile", { path: "$.temporary" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().delete("profile", "$.temporary") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONDel(context.Background(), "profile", "$.temporary").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonDel("profile", new redis.clients.jedis.json.Path("$.temporary")); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_del("profile", "$.temporary")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.FORGET +Source: https://upstash.com/docs/redis/commands/json/json-forget + +Use `JSON.FORGET` to alias for JSON.DEL. + +## Syntax + +```redis +JSON.FORGET [path] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | No | No | Path to delete; omitting it deletes the whole key. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.json.forget("key", "$.path.to.value"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().forget("profile", "$.temporary") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.FORGET", "profile", "$.temporary"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.forget("profile", { path: "$.temporary" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().forget("profile", "$.temporary") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONForget(context.Background(), "profile", "$.temporary").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonDel("profile", new redis.clients.jedis.json.Path("$.temporary")); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_del("profile", "$.temporary")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.GET +Source: https://upstash.com/docs/redis/commands/json/json-get + +Use `JSON.GET` to get JSON values. + +## Syntax + +```redis +JSON.GET [INDENT indent] [NEWLINE newline] [SPACE space] [path [path ...]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `INDENT indent` | No | No | Indentation characters for formatted JSON. | +| `NEWLINE newline` | No | No | Line-separator characters for formatted JSON. | +| `SPACE space` | No | No | Characters placed after JSON separators. | +| `path` | No | Yes | One or more paths; defaults to the root. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string or Null bulk string or null array | +| RESP3 | Bulk string or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const value = await redis.json.get("key", "$.path.to.somewhere"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().get("profile", "$.name") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.GET", "profile", "$.name"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.get("profile", { path: "$.name" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().get("profile", "$.name") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONGet(context.Background(), "profile", "$.name").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonGet("profile", new redis.clients.jedis.json.Path("$.name")); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_get("profile", &["$.name"])?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.MERGE +Source: https://upstash.com/docs/redis/commands/json/json-merge + +Use `JSON.MERGE` to merge JSON values. + +## Syntax + +```redis +JSON.MERGE +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | Yes | No | Path to merge into. | +| `value` | Yes | No | Valid JSON value containing the merge patch. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.json.merge("key", "$.path.to.value", {"new": "value"}) +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().merge("profile", "$", {"active": True}) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.MERGE", "profile", "$", "{\"active\":true}"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.merge("profile", "$", { active: true }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().merge("profile", "$", {"active": True}) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONMerge(context.Background(), "profile", "$", `{"active":true}`).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonMerge("profile", new redis.clients.jedis.json.Path("$"), java.util.Map.of("active", true)); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("JSON.MERGE"); + command.arg("profile"); + command.arg("$"); + command.arg("{\"active\":true}"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.MGET +Source: https://upstash.com/docs/redis/commands/json/json-mget + +Use `JSON.MGET` to get values from multiple keys. + +## Syntax + +```redis +JSON.MGET [key ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | Yes | One or more JSON document keys. | +| `path` | Yes | No | Path read from every key. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string JSON values or null values, one per key | +| RESP3 | Array of bulk-string JSON values or null values, one per key | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const values = await redis.json.mget(["key1", "key2"], "$.path.to.somewhere"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().mget(["profile:1", "profile:2"], "$.name") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.MGET", "profile:1", "profile:2", "$.name"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.mGet(["profile:1", "profile:2"], "$.name"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().mget(["profile:1", "profile:2"], "$.name") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONMGet(context.Background(), "$.name", "profile:1", "profile:2").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonMGet(new redis.clients.jedis.json.Path2("$.name"), "profile:1", "profile:2"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_mget(&["profile:1", "profile:2"], "$.name")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.MSET +Source: https://upstash.com/docs/redis/commands/json/json-mset + +Use `JSON.MSET` to set values in multiple keys. + +## Syntax + +```redis +JSON.MSET [key path value ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key path value` | Yes | Yes | One or more key, path, and valid-JSON-value triples. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.json.mset([ + { key: "profile:1", path: "$", value: { name: "Ada" } }, +]); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().mset([("profile:1", "$", {"name": "Ada"})]) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.MSET", "profile:1", "$", "{\"name\":\"Ada\"}"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.mSet([{ key: "profile:1", path: "$", value: { name: "Ada" } }]); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().mset([("profile:1", "$", {"name": "Ada"})]) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONMSet(context.Background(), "profile:1", "$", `{"name":"Ada"}`).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; +import java.nio.charset.StandardCharsets; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.commands.ProtocolCommand; + +ProtocolCommand command = () -> "JSON.MSET".getBytes(StandardCharsets.UTF_8); +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.sendCommand(command, "profile:1", "$", "{\"name\":\"Ada\"}"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("JSON.MSET"); + command.arg("profile:1"); + command.arg("$"); + command.arg("{\"name\":\"Ada\"}"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.NUMINCRBY +Source: https://upstash.com/docs/redis/commands/json/json-numincrby + +Use `JSON.NUMINCRBY` to increment JSON number. + +## Syntax + +```redis +JSON.NUMINCRBY +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | Yes | No | Path selecting numbers. | +| `value` | Yes | No | Numeric amount to add. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string containing a JSON number or array | +| RESP3 | Bulk string containing a JSON number or array | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const newValue = await redis.json.numincrby("key", "$.path.to.value", 2); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().numincrby("profile", "$.visits", 1) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.NUMINCRBY", "profile", "$.visits", "1"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.numIncrBy("profile", "$.visits", 1); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().numincrby("profile", "$.visits", 1) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONNumIncrBy(context.Background(), "profile", "$.visits", 1).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonNumIncrBy("profile", new redis.clients.jedis.json.Path("$.visits"), 1); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_num_incr_by("profile", "$.visits", 1)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.NUMMULTBY +Source: https://upstash.com/docs/redis/commands/json/json-nummultby + +Use `JSON.NUMMULTBY` to multiply JSON number. + +## Syntax + +```redis +JSON.NUMMULTBY +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | Yes | No | Path selecting numbers. | +| `value` | Yes | No | Numeric multiplier. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string containing a JSON number or array | +| RESP3 | Bulk string containing a JSON number or array | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const newValue = await redis.json.nummultby("key", "$.path.to.value", 2); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().nummultby("profile", "$.score", 2) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.NUMMULTBY", "profile", "$.score", "2"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.numMultBy("profile", "$.score", 2); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().nummultby("profile", "$.score", 2) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Do(context.Background(), "JSON.NUMMULTBY", "profile", "$.score", "2").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; +import java.nio.charset.StandardCharsets; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.commands.ProtocolCommand; + +ProtocolCommand command = () -> "JSON.NUMMULTBY".getBytes(StandardCharsets.UTF_8); +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.sendCommand(command, "profile", "$.score", "2"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("JSON.NUMMULTBY"); + command.arg("profile"); + command.arg("$.score"); + command.arg("2"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.OBJKEYS +Source: https://upstash.com/docs/redis/commands/json/json-objkeys + +Use `JSON.OBJKEYS` to get JSON object keys. + +## Syntax + +```redis +JSON.OBJKEYS [path] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | No | No | Path selecting objects; defaults to the root. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of arrays of bulk-string object keys or null values, or Null bulk string or null array | +| RESP3 | Array of arrays of bulk-string object keys or null values, or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const keys = await redis.json.objkeys("key", "$.path"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().objkeys("profile", "$") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.OBJKEYS", "profile", "$"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.objKeys("profile", { path: "$" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().objkeys("profile", "$") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONObjKeys(context.Background(), "profile", "$").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonObjKeys("profile", new redis.clients.jedis.json.Path("$")); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_obj_keys("profile", "$")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.OBJLEN +Source: https://upstash.com/docs/redis/commands/json/json-objlen + +Use `JSON.OBJLEN` to get JSON object size. + +## Syntax + +```redis +JSON.OBJLEN [path] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | No | No | Path selecting objects; defaults to the root. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer, array of integer lengths or null values, or Null bulk string or null array | +| RESP3 | Integer, array of integer lengths or null values, or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const lengths = await redis.json.objlen("key", "$.path"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().objlen("profile", "$") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.OBJLEN", "profile", "$"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.objLen("profile", { path: "$" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().objlen("profile", "$") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONObjLen(context.Background(), "profile", "$").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonObjLen("profile", new redis.clients.jedis.json.Path("$")); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_obj_len("profile", "$")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.RESP +Source: https://upstash.com/docs/redis/commands/json/json-resp + +Use `JSON.RESP` to get JSON in RESP format. + +## Syntax + +```redis +JSON.RESP [path] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | No | No | Path to convert; defaults to the root. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Nested array, Integer, Bulk string, Simple string (`true` or `false` for JSON booleans), or Null bulk string or null array | +| RESP3 | Nested array, Integer, Bulk string, Simple string (`true` or `false` for JSON booleans), or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.json.resp("profile", "$"); +console.log(result); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().resp("profile", "$") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.RESP", "profile", "$"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.sendCommand(["JSON.RESP", "profile", "$"]); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().resp("profile", "$") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Do(context.Background(), "JSON.RESP", "profile", "$").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; +import java.nio.charset.StandardCharsets; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.commands.ProtocolCommand; + +ProtocolCommand command = () -> "JSON.RESP".getBytes(StandardCharsets.UTF_8); +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.sendCommand(command, "profile", "$"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("JSON.RESP"); + command.arg("profile"); + command.arg("$"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.SET +Source: https://upstash.com/docs/redis/commands/json/json-set + +Use `JSON.SET` to set JSON value. + +## Syntax + +```redis +JSON.SET [NX | XX] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | Yes | No | Path to create or replace. | +| `value` | Yes | No | Valid JSON value. | +| `NX \| XX` | No | No | Write only when the path is absent (`NX`) or present (`XX`). | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK`, or Null bulk string or null array when `NX` or `XX` prevented the write | +| RESP3 | Simple string `OK`, or Null when `NX` or `XX` prevented the write | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +redis.json.set(key, "$.path", value); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().set("profile", "$", {"name": "Ada"}) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.SET", "profile", "$", "{\"name\":\"Ada\"}"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.set("profile", "$", { name: "Ada" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().set("profile", "$", {"name": "Ada"}) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONSet(context.Background(), "profile", "$", map[string]interface{}{"name": "Ada"}).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonSet("profile", new redis.clients.jedis.json.Path("$"), java.util.Map.of("name", "Ada")); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_set("profile", "$", &serde_json::json!({"name": "Ada"}))?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.STRAPPEND +Source: https://upstash.com/docs/redis/commands/json/json-strappend + +Use `JSON.STRAPPEND` to append to JSON string. + +## Syntax + +```redis +JSON.STRAPPEND +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | Yes | No | Path selecting strings. | +| `value` | Yes | No | JSON-encoded string to append. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer, array of integer lengths or null values, or Null bulk string or null array | +| RESP3 | Integer, array of integer lengths or null values, or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.json.strappend("key", "$.path.to.str", "abc"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().strappend("profile", "$.name", " Lovelace") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.STRAPPEND", "profile", "$.name", "\" Lovelace\""); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.strAppend("profile", " Lovelace", { path: "$.name" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().strappend("profile", " Lovelace", "$.name") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONStrAppend(context.Background(), "profile", "$.name", `" Lovelace"`).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonStrAppend("profile", new redis.clients.jedis.json.Path("$.name"), " Lovelace"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_str_append("profile", "$.name", " Lovelace")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.STRLEN +Source: https://upstash.com/docs/redis/commands/json/json-strlen + +Use `JSON.STRLEN` to get JSON string length. + +## Syntax + +```redis +JSON.STRLEN [path] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | No | No | Path selecting strings; defaults to the root. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer, array of integer lengths or null values, or Null bulk string or null array | +| RESP3 | Integer, array of integer lengths or null values, or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.json.strlen("key", "$.path.to.str", "a"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().strlen("profile", "$.name") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.STRLEN", "profile", "$.name"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.strLen("profile", { path: "$.name" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().strlen("profile", "$.name") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONStrLen(context.Background(), "profile", "$.name").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonStrLen("profile", new redis.clients.jedis.json.Path("$.name")); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_str_len("profile", "$.name")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.TOGGLE +Source: https://upstash.com/docs/redis/commands/json/json-toggle + +Use `JSON.TOGGLE` to toggle JSON boolean. + +## Syntax + +```redis +JSON.TOGGLE +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | Yes | No | Path selecting Boolean values. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of integer Boolean values or null values, one per matched path | +| RESP3 | Array of integer Boolean values or null values, one per matched path | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const bool = await redis.json.toggle("key", "$.path.to.bool"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().toggle("profile", "$.active") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.TOGGLE", "profile", "$.active"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.toggle("profile", "$.active"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().toggle("profile", "$.active") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONToggle(context.Background(), "profile", "$.active").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonToggle("profile", new redis.clients.jedis.json.Path("$.active")); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_toggle("profile", "$.active")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON.TYPE +Source: https://upstash.com/docs/redis/commands/json/json-type + +Use `JSON.TYPE` to get JSON value type. + +## Syntax + +```redis +JSON.TYPE [path] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `key` | Yes | No | JSON document key. | +| `path` | No | No | Path to inspect; defaults to the root. | + +## Important points + +* Raw TCP examples pass JSON values as valid JSON text. Typed Upstash SDK helpers serialize native objects and values for you. +* Paths beginning with `$` use JSONPath and can match multiple values, so many JSON commands return an array of per-match results. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string, array of bulk-string type names, or Null bulk string or null array | +| RESP3 | Bulk string, array of bulk-string type names, or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const myType = await redis.json.type("key", "$.path.to.value"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.json().type("profile", "$.name") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.call("JSON.TYPE", "profile", "$.name"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.json.type("profile", { path: "$.name" }); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.json().type("profile", "$.name") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.JSONType(context.Background(), "profile", "$.name").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.JedisPooled; + +try (JedisPooled jedis = new JedisPooled(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.jsonType("profile", new redis.clients.jedis.json.Path("$.name")); + System.out.println(result); +} +``` + + + + + +```rust +use redis::JsonCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: redis::Value = connection.json_type("profile", "$.name")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# JSON commands +Source: https://upstash.com/docs/redis/commands/json/overview + +To query inside JSON values (full-text, fuzzy, phrase, regex), see [Upstash Redis Search](/docs/redis/search/introduction). + + +Append values to JSON array +Find index of value in array +Insert values into JSON array +Get JSON array length +Pop value from JSON array +Trim JSON array to range +Clear JSON values +Delete JSON values +Inspect JSON memory usage +Alias for JSON.DEL +Get JSON values +Merge JSON values +Get values from multiple keys +Set values in multiple keys +Increment JSON number +Multiply JSON number +Get JSON object keys +Get JSON object size +Get JSON in RESP format +Set JSON value +Append to JSON string +Get JSON string length +Toggle JSON boolean +Get JSON value type + + +# BLMOVE +Source: https://upstash.com/docs/redis/commands/list/blmove + +Use `BLMOVE` to move an element from one list to another, blocking until the source has an element or the timeout expires. + +## Syntax + +```redis +BLMOVE (LEFT | RIGHT) (LEFT | RIGHT) +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key used as source. | +| `` | Yes | No | Redis key used as destination. | +| `(LEFT \| RIGHT)` | Yes | No | Choose one form: `LEFT`; `RIGHT`. | +| `(LEFT \| RIGHT)` | Yes | No | Choose one form: `LEFT`; `RIGHT`. | +| `` | Yes | No | Seconds to block; `0` blocks indefinitely. | + +## Important points + +* A blocking form holds the request until data arrives or its timeout expires. Set the client/network timeout longer than the command timeout. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string or Null bulk string or null array | +| RESP3 | Bulk string or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.blmove("source-key", "destination-key", "LEFT", "LEFT", "1.5"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.blMove("source-key", "destination-key", "LEFT", "LEFT", 1.5); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.blmove("source-key", "destination-key", 1.5, "LEFT", "LEFT") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.BLMove(context.Background(), "source-key", "destination-key", "LEFT", "LEFT", 1500*time.Millisecond).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.blmove("source-key", "destination-key", redis.clients.jedis.args.ListDirection.LEFT, redis.clients.jedis.args.ListDirection.LEFT, 1.5); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("BLMOVE"); + command.arg("source-key"); + command.arg("destination-key"); + command.arg("LEFT"); + command.arg("LEFT"); + command.arg("1.5"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# BLMPOP +Source: https://upstash.com/docs/redis/commands/list/blmpop + +Use `BLMPOP` to pop elements from the first non-empty list among several, blocking until one has elements or the timeout expires. + +## Syntax + +```redis +BLMPOP [ ...] (LEFT | RIGHT) [COUNT ] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Seconds to block; `0` blocks indefinitely. | +| `` | Yes | No | Number of key arguments that follow. | +| `` | Yes | Yes | Redis key targeted by the command. | +| `(LEFT \| RIGHT)` | Yes | No | Choose one form: `LEFT`; `RIGHT`. | +| `COUNT ` | No | No | Maximum number of elements to pop. | + +## Important points + +* A blocking form holds the request until data arrives or its timeout expires. Set the client/network timeout longer than the command timeout. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Null bulk string or null array, or two-element array: key and array of values | +| RESP3 | Null, or two-element array: key and array of values | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.blmpop("1.5", "1", "my-key", "LEFT"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.blmPop(1.5, "my-key", "LEFT"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.blmpop(1.5, 1, "my-key", direction="LEFT") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + _, result, err := client.BLMPop(context.Background(), 1500*time.Millisecond, "LEFT", 0, "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.blmpop(1.5, redis.clients.jedis.args.ListDirection.LEFT, "my-key"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("BLMPOP"); + command.arg("1.5"); + command.arg("1"); + command.arg("my-key"); + command.arg("LEFT"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# BLPOP +Source: https://upstash.com/docs/redis/commands/list/blpop + +Use `BLPOP` to pop an element from the head of the first non-empty list, blocking until one has an element or the timeout expires. + +## Syntax + +```redis +BLPOP [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | Yes | Redis key targeted by the command. | +| `` | Yes | No | Seconds to block; `0` blocks indefinitely. | + +## Important points + +* A blocking form holds the request until data arrives or its timeout expires. Set the client/network timeout longer than the command timeout. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Null bulk string or null array, or two-element key/value array | +| RESP3 | Null, or two-element key/value array | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.blpop("my-key", "1.5"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.blPop("my-key", 1.5); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.blpop(["my-key"], timeout=1.5) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.BLPop(context.Background(), 1500*time.Millisecond, "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.blpop(1.5, "my-key"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("BLPOP"); + command.arg("my-key"); + command.arg("1.5"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# BRPOP +Source: https://upstash.com/docs/redis/commands/list/brpop + +Use `BRPOP` to pop an element from the tail of the first non-empty list, blocking until one has an element or the timeout expires. + +## Syntax + +```redis +BRPOP [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | Yes | Redis key targeted by the command. | +| `` | Yes | No | Seconds to block; `0` blocks indefinitely. | + +## Important points + +* A blocking form holds the request until data arrives or its timeout expires. Set the client/network timeout longer than the command timeout. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Null bulk string or null array, or two-element key/value array | +| RESP3 | Null, or two-element key/value array | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.brpop("my-key", "1.5"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.brPop("my-key", 1.5); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.brpop(["my-key"], timeout=1.5) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.BRPop(context.Background(), 1500*time.Millisecond, "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.brpop(1.5, "my-key"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("BRPOP"); + command.arg("my-key"); + command.arg("1.5"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# BRPOPLPUSH +Source: https://upstash.com/docs/redis/commands/list/brpoplpush + +Use `BRPOPLPUSH` to pop an element from the tail of one list and push it to the head of another, blocking until the source has an element or the timeout expires. + +## Syntax + +```redis +BRPOPLPUSH +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key used as source. | +| `` | Yes | No | Redis key used as destination. | +| `` | Yes | No | Seconds to block; `0` blocks indefinitely. | + +## Important points + +* A blocking form holds the request until data arrives or its timeout expires. Set the client/network timeout longer than the command timeout. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string or Null bulk string or null array | +| RESP3 | Bulk string or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.brpoplpush("source-key", "destination-key", "1.5"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.brPopLPush("source-key", "destination-key", 1.5); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.brpoplpush("source-key", "destination-key", timeout=1.5) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.BRPopLPush(context.Background(), "source-key", "destination-key", 1500*time.Millisecond).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.brpoplpush("source-key", "destination-key", 1); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("BRPOPLPUSH"); + command.arg("source-key"); + command.arg("destination-key"); + command.arg("1.5"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LINDEX +Source: https://upstash.com/docs/redis/commands/list/lindex + +Use `LINDEX` to get element by index. + +## Syntax + +```redis +LINDEX +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Zero-based index; negative values count from the end. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Null bulk string or null array or Bulk string | +| RESP3 | Null or Bulk string | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.rpush("key", "a", "b", "c"); +const element = await redis.lindex("key", 0); +console.log(element); // "a" +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.lindex("my-key", 0) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.lindex("my-key", "0"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lIndex("my-key", 0); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.lindex("my-key", 0) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.LIndex(context.Background(), "my-key", 0).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.lindex("my-key", 0); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.lindex("my-key", 0)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LINSERT +Source: https://upstash.com/docs/redis/commands/list/linsert + +Use `LINSERT` to insert before or after pivot. + +## Syntax + +```redis +LINSERT (BEFORE | AFTER) +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `(BEFORE \| AFTER)` | Yes | No | Choose one form: `BEFORE`; `AFTER`. | +| `` | Yes | No | Existing element to insert next to. | +| `` | Yes | No | Element to insert. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer: the list length after insertion, `-1` if the pivot was not found, `0` if the key does not exist | +| RESP3 | Integer: the list length after insertion, `-1` if the pivot was not found, `0` if the key does not exist | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.rpush("key", "a", "b", "c"); +await redis.linsert("key", "before", "b", "x"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.linsert("my-key", "BEFORE", "pivot", "element") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.linsert("my-key", "BEFORE", "pivot", "element"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lInsert("my-key", "BEFORE", "pivot", "element"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.linsert("my-key", "BEFORE", "pivot", "element") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.LInsertBefore(context.Background(), "my-key", "pivot", "element").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.linsert("my-key", redis.clients.jedis.args.ListPosition.BEFORE, "pivot", "element"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.linsert_before("my-key", "pivot", "element")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LLEN +Source: https://upstash.com/docs/redis/commands/list/llen + +Use `LLEN` to get list length. + +## Syntax + +```redis +LLEN +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.rpush("key", "a", "b", "c"); +const length = await redis.llen("key"); +console.log(length); // 3 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.llen("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.llen("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lLen("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.llen("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.LLen(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.llen("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.llen("my-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LMOVE +Source: https://upstash.com/docs/redis/commands/list/lmove + +Use `LMOVE` to move element between lists. + +## Syntax + +```redis +LMOVE (LEFT | RIGHT) (LEFT | RIGHT) +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key used as source. | +| `` | Yes | No | Redis key used as destination. | +| `(LEFT \| RIGHT)` | Yes | No | Choose one form: `LEFT`; `RIGHT`. | +| `(LEFT \| RIGHT)` | Yes | No | Choose one form: `LEFT`; `RIGHT`. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string | +| RESP3 | Bulk string | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.rpush("source", "a", "b", "c"); +const element = await redis.lmove("source", "destination", "left", "left"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.lmove("source-key", "destination-key", "LEFT", "LEFT") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.lmove("source-key", "destination-key", "LEFT", "LEFT"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lMove("source-key", "destination-key", "LEFT", "LEFT"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.lmove("source-key", "destination-key", "LEFT", "LEFT") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.LMove(context.Background(), "source-key", "destination-key", "LEFT", "LEFT").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.lmove("source-key", "destination-key", redis.clients.jedis.args.ListDirection.LEFT, redis.clients.jedis.args.ListDirection.LEFT); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.lmove("source-key", "destination-key", redis::Direction::Left, redis::Direction::Left)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LMPOP +Source: https://upstash.com/docs/redis/commands/list/lmpop + +Use `LMPOP` to pop from multiple lists. + +## Syntax + +```redis +LMPOP [ ...] (LEFT | RIGHT) [COUNT ] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Number of key arguments that follow. | +| `` | Yes | Yes | Redis key targeted by the command. | +| `(LEFT \| RIGHT)` | Yes | No | Choose one form: `LEFT`; `RIGHT`. | +| `COUNT ` | No | No | Maximum number of elements to pop. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Null bulk string or null array, or two-element array: key and array of values | +| RESP3 | Null, or two-element array: key and array of values | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); +const result = await redis.lmpop(1, ["my-key"], "LEFT"); +console.log(result); +``` + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.lmpop("1", "my-key", "LEFT"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lmPop("my-key", "LEFT"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.lmpop(1, "my-key", direction="LEFT") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + _, result, err := client.LMPop(context.Background(), "LEFT", 0, "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.lmpop(redis.clients.jedis.args.ListDirection.LEFT, "my-key"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("LMPOP"); + command.arg("1"); + command.arg("my-key"); + command.arg("LEFT"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LPOP +Source: https://upstash.com/docs/redis/commands/list/lpop + +Use `LPOP` to pop from list head. + +## Syntax + +```redis +LPOP [] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | No | No | Number of elements to pop. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Null bulk string or null array, Bulk string, or array of bulk-string values | +| RESP3 | Null, Bulk string, or array of bulk-string values | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.rpush("key", "a", "b", "c"); +const element = await redis.lpop("key"); +console.log(element); // "a" +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.lpop("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.lpop("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lPop("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.lpop("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.LPop(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.lpop("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: Option = connection.lpop("my-key", None)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LPOS +Source: https://upstash.com/docs/redis/commands/list/lpos + +Use `LPOS` to find element position. + +## Syntax + +```redis +LPOS [RANK ] [COUNT ] [MAXLEN ] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Element value to search for. | +| `RANK ` | No | No | Which match to return; negative values search from the tail. | +| `COUNT ` | No | No | Number of matches to return; `0` returns every match. | +| `MAXLEN ` | No | No | Maximum number of entries to keep in the stream. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Null bulk string or null array, Integer, or array of integer positions | +| RESP3 | Null, Integer, or array of integer positions | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.rpush("key", "a", "b", "c"); +const index = await redis.lpos("key", "b"); +console.log(index); // 1 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.lpos("my-key", "element") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.lpos("my-key", "element"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lPos("my-key", "element"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.lpos("my-key", "element") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.LPos(context.Background(), "my-key", "element", redis.LPosArgs{}).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.lpos("my-key", "element"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("LPOS"); + command.arg("my-key"); + command.arg("element"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LPUSH +Source: https://upstash.com/docs/redis/commands/list/lpush + +Use `LPUSH` to push to list head. + +## Syntax + +```redis +LPUSH [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | Yes | Element to push. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const length1 = await redis.lpush("key", "a", "b", "c"); +console.log(length1); // 3 +const length2 = await redis.lpush("key", "d"); +console.log(length2); // 4 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.lpush("my-key", "element") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.lpush("my-key", "element"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lPush("my-key", "element"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.lpush("my-key", "element") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.LPush(context.Background(), "my-key", "element").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.lpush("my-key", "element"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.lpush("my-key", "element")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LPUSHX +Source: https://upstash.com/docs/redis/commands/list/lpushx + +Use `LPUSHX` to push to head if list exists. + +## Syntax + +```redis +LPUSHX [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | Yes | Element to push. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.lpush("key", "a", "b", "c"); +const length = await redis.lpushx("key", "d"); +console.log(length); // 4 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.lpushx("my-key", "element") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.lpushx("my-key", "element"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lPushX("my-key", "element"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.lpushx("my-key", "element") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.LPushX(context.Background(), "my-key", "element").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.lpushx("my-key", "element"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.lpush_exists("my-key", "element")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LRANGE +Source: https://upstash.com/docs/redis/commands/list/lrange + +Use `LRANGE` to get range of elements. + +## Syntax + +```redis +LRANGE +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Start index; negative values count from the end. | +| `` | Yes | No | Stop index, inclusive; negative values count from the end. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of bulk-string values | +| RESP3 | Array of bulk-string values | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.lpush("key", "a", "b", "c"); +const elements = await redis.lrange("key", 1, 2); +console.log(elements) // ["b", "c"] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.lrange("my-key", 0, 0) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.lrange("my-key", "0", "0"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lRange("my-key", 0, 0); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.lrange("my-key", 0, 0) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.LRange(context.Background(), "my-key", 0, 0).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.lrange("my-key", 0, 0); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.lrange("my-key", 0, 0)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LREM +Source: https://upstash.com/docs/redis/commands/list/lrem + +Use `LREM` to remove elements by value. + +## Syntax + +```redis +LREM +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | How many matches to remove: positive scans head to tail, negative tail to head, `0` removes every match. | +| `` | Yes | No | Element value to remove. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.lpush("key", "a", "a", "b", "b", "c"); +const removed = await redis.lrem("key", 4, "b"); +console.log(removed) // 2 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.lrem("my-key", 1, "element") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.lrem("my-key", "1", "element"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lRem("my-key", 1, "element"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.lrem("my-key", 1, "element") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.LRem(context.Background(), "my-key", 1, "element").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.lrem("my-key", 1, "element"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.lrem("my-key", 1, "element")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LSET +Source: https://upstash.com/docs/redis/commands/list/lset + +Use `LSET` to set element at index. + +## Syntax + +```redis +LSET +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Zero-based index; negative values count from the end. | +| `` | Yes | No | Element to store at the index. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.lpush("key", "a", "b", "c"); +await redis.lset("key", 1, "d"); + +// list is now ["a", "d", "c"] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.lset("my-key", 0, "element") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.lset("my-key", "0", "element"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lSet("my-key", 0, "element"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.lset("my-key", 0, "element") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.LSet(context.Background(), "my-key", 0, "element").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.lset("my-key", 0, "element"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.lset("my-key", 0, "element")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# LTRIM +Source: https://upstash.com/docs/redis/commands/list/ltrim + +Use `LTRIM` to trim list to range. + +## Syntax + +```redis +LTRIM +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | No | Start index; negative values count from the end. | +| `` | Yes | No | Stop index, inclusive; negative values count from the end. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Simple string `OK` | +| RESP3 | Simple string `OK` | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.lpush("key", "a", "b", "c", "d"); +await redis.ltrim("key", 1, 2); +// the list is now ["b", "c"] +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.ltrim("my-key", 0, 0) +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.ltrim("my-key", "0", "0"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.lTrim("my-key", 0, 0); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.ltrim("my-key", 0, 0) +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.LTrim(context.Background(), "my-key", 0, 0).Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.ltrim("my-key", 0, 0); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.ltrim("my-key", 0, 0)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# List commands +Source: https://upstash.com/docs/redis/commands/list/overview + + +Blocking list move +Blocking pop from multiple lists +Blocking left pop +Blocking right pop +Blocking pop and push +Get element by index +Insert before or after pivot +Get list length +Move element between lists +Pop from multiple lists +Pop from list head +Find element position +Push to list head +Push to head if list exists +Get range of elements +Remove elements by value +Set element at index +Trim list to range +Pop from list tail +Pop from tail and push to head +Push to list tail +Push to tail if list exists + + +# RPOP +Source: https://upstash.com/docs/redis/commands/list/rpop + +Use `RPOP` to pop from list tail. + +## Syntax + +```redis +RPOP [] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | No | No | Number of elements to pop. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Null bulk string or null array, Bulk string, or array of bulk-string values | +| RESP3 | Null, Bulk string, or array of bulk-string values | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.rpush("key", "a", "b", "c"); +const element = await redis.rpop("key"); +console.log(element); // "c" +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.rpop("my-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.rpop("my-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.rPop("my-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.rpop("my-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.RPop(context.Background(), "my-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.rpop("my-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result: Option = connection.rpop("my-key", None)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# RPOPLPUSH +Source: https://upstash.com/docs/redis/commands/list/rpoplpush + +Use `RPOPLPUSH` to pop from tail and push to head. + +## Syntax + +```redis +RPOPLPUSH +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key used as source. | +| `` | Yes | No | Redis key used as destination. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Bulk string or Null bulk string or null array | +| RESP3 | Bulk string or Null | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.rpoplpush("source-key", "destination-key") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.rpoplpush("source-key", "destination-key"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.rPopLPush("source-key", "destination-key"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.rpoplpush("source-key", "destination-key") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.RPopLPush(context.Background(), "source-key", "destination-key").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.rpoplpush("source-key", "destination-key"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.rpoplpush("source-key", "destination-key")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# RPUSH +Source: https://upstash.com/docs/redis/commands/list/rpush + +Use `RPUSH` to push to list tail. + +## Syntax + +```redis +RPUSH [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | Yes | Element to push. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const length1 = await redis.rpush("key", "a", "b", "c"); +console.log(length1); // 3 +const length2 = await redis.rpush("key", "d"); +console.log(length2); // 4 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.rpush("my-key", "element") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.rpush("my-key", "element"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.rPush("my-key", "element"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.rpush("my-key", "element") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.RPush(context.Background(), "my-key", "element").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.rpush("my-key", "element"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.rpush("my-key", "element")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# RPUSHX +Source: https://upstash.com/docs/redis/commands/list/rpushx + +Use `RPUSHX` to push to tail if list exists. + +## Syntax + +```redis +RPUSHX [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Redis key targeted by the command. | +| `` | Yes | Yes | Element to push. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +await redis.lpush("key", "a", "b", "c"); +const length = await redis.rpushx("key", "d"); +console.log(length); // 4 +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.rpushx("my-key", "element") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.rpushx("my-key", "element"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.rPushX("my-key", "element"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.rpushx("my-key", "element") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.RPushX(context.Background(), "my-key", "element").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.rpushx("my-key", "element"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.rpush_exists("my-key", "element")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# Redis command reference +Source: https://upstash.com/docs/redis/commands/overview + +Upstash supports Redis commands over both native Redis TCP and HTTPS REST. Choose a category to browse its supported commands. + + +Manipulate individual bits and bit fields +Authenticate and manage client connections +Load, manage, and invoke Redis functions +Manage keys, expiration, and serialization +Store and query geospatial data +Work with field-value collections +Estimate cardinality +Store and manipulate JSON values +Work with ordered collections +Publish messages and manage subscriptions +Load and execute Lua scripts +Create, query, and manage search indexes +Inspect and manage the Redis server +Work with unique unordered members +Work with scored collections +Process append-only logs and consumer groups +Store and manipulate string values +Group operations into atomic transactions + + +# Pub/Sub commands +Source: https://upstash.com/docs/redis/commands/pub-sub/overview + + +Subscribe to pattern channels +Publish message to channel +Inspect pub/sub state +Unsubscribe from patterns +Subscribe to channels +Unsubscribe from channels + + +# PSUBSCRIBE +Source: https://upstash.com/docs/redis/commands/pub-sub/psubscribe + +Use `PSUBSCRIBE` to subscribe to pattern channels. + +## Syntax + +```redis +PSUBSCRIBE [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | Yes | Glob-style channel pattern. | + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. +* Subscription commands require a dedicated TCP connection. In RESP3, subscription events use push replies. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Three-element subscription-state array per pattern | +| RESP3 | Three-element subscription-state push reply per pattern | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const subscriber = new Redis(process.env.REDIS_URL!); +await subscriber.psubscribe("events:*"); +subscriber.on("message", (channel, message) => console.log(channel, message)); +``` + + + + + +```ts +import { createClient } from "redis"; + +const subscriber = await createClient({ url: process.env.REDIS_URL }).connect(); +await subscriber.pSubscribe("events:*", (message, channel) => { + console.log(channel, message); +}); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +pubsub = client.pubsub() +pubsub.psubscribe("events:*") +for message in pubsub.listen(): + print(message) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + ctx := context.Background() + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + pubsub := client.PSubscribe(ctx, "events:*") + for message := range pubsub.Channel() { + fmt.Println(message.Channel, message.Payload) + } +} +``` + + + + + +```java +import java.net.URI; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPubSub; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + jedis.psubscribe(new JedisPubSub() { + @Override + public void onPMessage(String pattern, String channel, String message) { + System.out.println(channel + ": " + message); + } + }, "events:*"); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + let mut pubsub = connection.as_pubsub(); + pubsub.psubscribe("events:*")?; + loop { + let message = pubsub.get_message()?; + let payload: String = message.get_payload()?; + println!("{payload}"); + } + #[allow(unreachable_code)] + Ok(()) +} +``` + + + + + +# PUBLISH +Source: https://upstash.com/docs/redis/commands/pub-sub/publish + +Use `PUBLISH` to publish message to channel. + +## Syntax + +```redis +PUBLISH +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | No | Channel name. | +| `` | Yes | No | Message payload. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Integer | +| RESP3 | Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import { Redis } from "@upstash/redis"; + +const redis = Redis.fromEnv(); + +const listeners = await redis.publish("my-channel", "my-message"); +``` + + + + + +```python +from upstash_redis import Redis + +redis = Redis.from_env() +result = redis.publish("events", "hello") +print(result) +``` + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.publish("events", "hello"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.publish("events", "hello"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.publish("events", "hello") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.Publish(context.Background(), "events", "hello").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.publish("events", "hello"); + System.out.println(result); +} +``` + + + + + +```rust +use redis::TypedCommands; + +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let result = connection.publish("events", "hello")?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# PUBSUB +Source: https://upstash.com/docs/redis/commands/pub-sub/pubsub + +Use `PUBSUB` to inspect pub/sub state. + +## Syntax + +```redis +PUBSUB CHANNELS [pattern] +PUBSUB NUMSUB [channel ...] +PUBSUB NUMPAT +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `CHANNELS [pattern]` | One form | No | List active channels, optionally filtered by a glob-style pattern. | +| `NUMSUB [channel ...]` | One form | Yes | Return subscriber counts for the supplied channels. | +| `NUMPAT` | One form | No | Return the number of active pattern subscriptions. | + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Array of channel names, flat channel/count array, or Integer | +| RESP3 | Array of channel names, flat channel/count array, or Integer | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + + + This command is not supported yet in `@upstash/redis`. + + + + + + + + This command is not supported yet in `upstash_redis`. + + + + + + +```ts +import Redis from "ioredis"; + +const redis = new Redis(process.env.REDIS_URL!); +const result = await redis.pubsub("CHANNELS", "events:*"); +console.log(result); +``` + + + + + +```ts +import { createClient } from "redis"; + +const client = await createClient({ url: process.env.REDIS_URL }) + .on("error", console.error) + .connect(); +const result = await client.pubSubChannels("events:*"); +console.log(result); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +result = client.pubsub_channels("events:*") +print(result) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + result, err := client.PubSubChannels(context.Background(), "events:*").Result() + if err != nil { + panic(err) + } + fmt.Println(result) +} +``` + + + + + +```java +import java.net.URI; + +import redis.clients.jedis.Jedis; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + Object result = jedis.pubsubChannels("events:*"); + System.out.println(result); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + + let mut command = redis::cmd("PUBSUB"); + command.arg("CHANNELS"); + command.arg("events:*"); + let result: redis::Value = command.query(&mut connection)?; + println!("{result:?}"); + Ok(()) +} +``` + + + + + +# PUNSUBSCRIBE +Source: https://upstash.com/docs/redis/commands/pub-sub/punsubscribe + +Use `PUNSUBSCRIBE` to unsubscribe from patterns. + +## Syntax + +```redis +PUNSUBSCRIBE [ [ ...]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | No | Yes | Glob-style channel pattern; omit to unsubscribe from all patterns. | + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. +* Subscription commands require a dedicated TCP connection. In RESP3, subscription events use push replies. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Three-element subscription-state array per pattern | +| RESP3 | Three-element subscription-state push reply per pattern | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const subscriber = new Redis(process.env.REDIS_URL!); +await subscriber.psubscribe("events:*"); +await subscriber.punsubscribe("events:*"); +``` + + + + + +```ts +import { createClient } from "redis"; + +const subscriber = await createClient({ url: process.env.REDIS_URL }).connect(); +await subscriber.pSubscribe("events:*", console.log); +await subscriber.pUnsubscribe("events:*"); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +pubsub = client.pubsub() +pubsub.psubscribe("events:*") +pubsub.punsubscribe("events:*") +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + ctx := context.Background() + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + pubsub := client.PSubscribe(ctx, "events:*") + if err := pubsub.PUnsubscribe(ctx, "events:*"); err != nil { + panic(err) + } +} +``` + + + + + +```java +import java.net.URI; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPubSub; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + jedis.psubscribe(new JedisPubSub() { + @Override + public void onPMessage(String pattern, String channel, String message) { + punsubscribe(); + } + }, "events:*"); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + let mut pubsub = connection.as_pubsub(); + pubsub.psubscribe("events:*")?; + pubsub.punsubscribe("events:*")?; + #[allow(unreachable_code)] + Ok(()) +} +``` + + + + + +# SUBSCRIBE +Source: https://upstash.com/docs/redis/commands/pub-sub/subscribe + +Use `SUBSCRIBE` to subscribe to channels. + +## Syntax + +```redis +SUBSCRIBE [ ...] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | Yes | Yes | Channel name. | + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. +* Subscription commands require a dedicated TCP connection. In RESP3, subscription events use push replies. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Three-element subscription-state array per channel | +| RESP3 | Three-element subscription-state push reply per channel | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const subscriber = new Redis(process.env.REDIS_URL!); +await subscriber.subscribe("events"); +subscriber.on("message", (channel, message) => console.log(channel, message)); +``` + + + + + +```ts +import { createClient } from "redis"; + +const subscriber = await createClient({ url: process.env.REDIS_URL }).connect(); +await subscriber.subscribe("events", (message, channel) => { + console.log(channel, message); +}); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +pubsub = client.pubsub() +pubsub.subscribe("events") +for message in pubsub.listen(): + print(message) +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + ctx := context.Background() + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + pubsub := client.Subscribe(ctx, "events") + for message := range pubsub.Channel() { + fmt.Println(message.Channel, message.Payload) + } +} +``` + + + + + +```java +import java.net.URI; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPubSub; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + jedis.subscribe(new JedisPubSub() { + @Override + public void onMessage(String channel, String message) { + System.out.println(channel + ": " + message); + } + }, "events"); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + let mut pubsub = connection.as_pubsub(); + pubsub.subscribe("events")?; + loop { + let message = pubsub.get_message()?; + let payload: String = message.get_payload()?; + println!("{payload}"); + } + #[allow(unreachable_code)] + Ok(()) +} +``` + + + + + +# UNSUBSCRIBE +Source: https://upstash.com/docs/redis/commands/pub-sub/unsubscribe + +Use `UNSUBSCRIBE` to unsubscribe from channels. + +## Syntax + +```redis +UNSUBSCRIBE [ [ ...]] +``` + +## Arguments + +| Argument | Required | Repeatable | Description | +| --- | --- | --- | --- | +| `` | No | Yes | Channel name. | + +## Important points + +* This is a connection-oriented command and is available over native Redis TCP, not the stateless REST endpoint. +* Subscription commands require a dedicated TCP connection. In RESP3, subscription events use push replies. + +## Response + +The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below. + +| Protocol | Reply | +| --- | --- | +| RESP2 | Three-element subscription-state array per channel | +| RESP3 | Three-element subscription-state push reply per channel | + + + Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply. + + +## Examples + +TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`. + + + + + +```ts +import Redis from "ioredis"; + +const subscriber = new Redis(process.env.REDIS_URL!); +await subscriber.subscribe("events"); +await subscriber.unsubscribe("events"); +``` + + + + + +```ts +import { createClient } from "redis"; + +const subscriber = await createClient({ url: process.env.REDIS_URL }).connect(); +await subscriber.subscribe("events", console.log); +await subscriber.unsubscribe("events"); +``` + + + + + +```python +import os +import redis + +client = redis.from_url(os.environ["REDIS_URL"]) +pubsub = client.pubsub() +pubsub.subscribe("events") +pubsub.unsubscribe("events") +``` + + + + + +```go +package main + +import ( + "context" + "fmt" + "os" + + "github.com/redis/go-redis/v9" +) + +func main() { + ctx := context.Background() + opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) + if err != nil { + panic(err) + } + client := redis.NewClient(opts) + pubsub := client.Subscribe(ctx, "events") + if err := pubsub.Unsubscribe(ctx, "events"); err != nil { + panic(err) + } +} +``` + + + + + +```java +import java.net.URI; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPubSub; + +try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { + jedis.subscribe(new JedisPubSub() { + @Override + public void onMessage(String channel, String message) { + unsubscribe(); + } + }, "events"); +} +``` + + + + + +```rust +fn main() -> redis::RedisResult<()> { + let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); + let client = redis::Client::open(url)?; + let mut connection = client.get_connection()?; + let mut pubsub = connection.as_pubsub(); + pubsub.subscribe("events")?; + pubsub.unsubscribe("events")?; + #[allow(unreachable_code)] + Ok(()) +} +``` + + + + + +# EVAL +Source: https://upstash.com/docs/redis/commands/scripting/eval + +Use `EVAL` to execute a Lua script. + +## Syntax + +```redis +EVAL