Skip to content

Latest commit

 

History

History
2160 lines (1251 loc) · 30.9 KB

File metadata and controls

2160 lines (1251 loc) · 30.9 KB

@devvit/public-api v0.13.11-dev


Interface: TxClientLike

Extends

  • TxClientLike

Methods

del()

del(...keys): Promise<TxClientLike>

Removes the specified keys. A key is ignored if it does not exist. https://redis.io/commands/del/

Parameters

keys

...string[]

Returns

Promise<TxClientLike>

Arg

keys

Example

async function delExample(context: Devvit.Context) {
 await context.redis.set("quantity", "5");
 await context.redis.del("quantity");
}

Inherited from

TxClientLikeBase.del


discard()

discard(): Promise<void>

Flushes all previously queued commands in a transaction and restores the connection state to normal. If WATCH was used, DISCARD unwatches all keys watched by the connection. https://redis.io/docs/latest/commands/discard/

Returns

Promise<void>

Example

async function discardExample(context: Devvit.Context) {
 await context.redis.set("price", "25");

 const txn = await context.redis.watch("price");

 await txn.multi();     // Begin a transaction
 await txn.incrby("price", 5);
 await txn.discard();   // Discard the commands in the transaction
}

Inherited from

TxClientLikeBase.discard


exec()

exec(): Promise<any[]>

Executes all previously queued commands in a transaction and restores the connection state to normal. https://redis.io/commands/exec/

Returns

Promise<any[]>

array, each element being the reply to each of the commands in the atomic transaction.

Example

async function execExample(context: Devvit.Context) {
 await context.redis.set("karma", "32");

 const txn = await context.redis.watch("quantity");

 await txn.multi();  // Begin a transaction
 await txn.incrby("karma", 10);
 await txn.exec();   // Execute the commands in the transaction
}

Inherited from

TxClientLikeBase.exec


expire()

expire(key, seconds): Promise<TxClientLike>

Set a timeout on key. https://redis.io/commands/expire/

Parameters

key

string

seconds

number

Returns

Promise<TxClientLike>

Arg

key

Arg

seconds

Example

async function expireExample(context: Devvit.Context) {
 await context.redis.set("product", "milk");
 await context.redis.expire("product", 60);   // Set the product to expire in 60 seconds
}

Inherited from

TxClientLikeBase.expire


expireTime()

expireTime(key): Promise<TxClientLike>

Returns the absolute Unix timestamp in seconds at which the given key will expire https://redis.io/commands/expiretime/

Parameters

key

string

Returns

Promise<TxClientLike>

expiration Unix timestamp in seconds, or a negative value in order to signal an error

Arg

key

Example

async function expireTimeExample(context: Devvit.Context) {
 await context.redis.set("product", "milk");
 const expireTime : number = await context.redis.expiretime("product");
 console.log("Expire time: " + expireTime);
}

Inherited from

TxClientLikeBase.expireTime


get()

get(key): Promise<TxClientLike>

Get the value of key. If the key does not exist the special value nil is returned. https://redis.io/commands/get/

Parameters

key

string

Returns

Promise<TxClientLike>

value of key or null when key does not exist.

Arg

key

Example

async function getExample(context: Devvit.Context) {
 await context.redis.set("quantity", "5");
 const quantity : string | undefined = await context.redis.get("quantity");
 console.log("Quantity: " + quantity);
}

Inherited from

TxClientLikeBase.get


getRange()

getRange(key, start, end): Promise<TxClientLike>

Returns the substring of the string value stored at key, determined by the offsets start and end (both are inclusive). https://redis.io/commands/getrange/

Parameters

key

string

start

number

end

number

Returns

Promise<TxClientLike>

substring determined by offsets [start, end]

Arg

key

Arg

start

Arg

end

Example

async function getRangeExample(context: Devvit.Context) {
 await context.redis.set("word", "tacocat");
 const range : string = await context.redis.getrange("word", 0, 3)
 console.log("Range from index 0 to 3: " + range);
}

Inherited from

TxClientLikeBase.getRange


hdel()

hdel(key, fields): Promise<TxClientLike>

Parameters

key

string

fields

string[]

Returns

Promise<TxClientLike>

Deprecated

Use TxClientLike.hDel instead.


hDel()

hDel(key, fields): Promise<TxClientLike>

Removes the specified fields from the hash stored at key. https://redis.io/commands/hdel/

Parameters

key

string

fields

string[]

Returns

Promise<TxClientLike>

number of fields that were removed from the hash

async function hDelExample(context: Devvit.Context) {
 await context.redis.hset("fruits", {"apple": "5", "orange": "7", "kiwi": "9"});
 const numFieldsRemoved = await context.redis.hdel("fruits", ["apple", "kiwi"]);
 console.log("Number of fields removed: " + numFieldsRemoved);
}

Arg

key

Arg

fields

Inherited from

TxClientLikeBase.hDel


hget()

hget(key, field): Promise<TxClientLike>

Parameters

key

string

field

string

Returns

Promise<TxClientLike>

Deprecated

Use TxClientLike.hGet instead.


hGet()

hGet(key, field): Promise<TxClientLike>

Returns the value associated with field in the hash stored at key. https://redis.io/commands/hget

Parameters

key

string

field

string

Returns

Promise<TxClientLike>

value associated with field

Arg

key

Arg

field

Example

async function hGetExample(context: Devvit.Context) {
 await context.redis.hset("fruits", {"apple": "5", "orange": "7", "kiwi": "9"});
 const result : string | undefined = await context.redis.hget("fruits", "orange");
 console.log("Value of orange: " + result);
}

Inherited from

TxClientLikeBase.hGet


hgetall()

hgetall(key): Promise<TxClientLike>

Parameters

key

string

Returns

Promise<TxClientLike>

Deprecated

Use TxClientLike.hGetAll instead.


hGetAll()

hGetAll(key): Promise<TxClientLike>

Returns all fields and values of the hash stored at key https://redis.io/commands/hgetall

Parameters

key

string

Returns

Promise<TxClientLike>

a map of fields and their values stored in the hash,

Arg

key

Example

async function hGetAllExample(context: Devvit.Context) {
 await context.redis.hset("groceryList", {
  "eggs": "12",
  "apples": "3",
  "milk": "1"
 });

 const record : Record<string, string> | undefined = await context.redis.hgetall("groceryList");

 if (record != undefined) {
  console.log("Eggs: " + record.eggs + ", Apples: " + record.apples + ", Milk: " + record.milk);
 }
}

Inherited from

TxClientLikeBase.hGetAll


hincrby()

hincrby(key, field, value): Promise<TxClientLike>

Parameters

key

string

field

string

value

number

Returns

Promise<TxClientLike>

Deprecated

Use TxClientLike.hIncrBy instead.


hIncrBy()

hIncrBy(key, field, value): Promise<TxClientLike>

Increments the number stored at field in the hash stored at key by increment. https://redis.io/commands/hincrby/

Parameters

key

string

field

string

value

number

Returns

Promise<TxClientLike>

value of key after the increment

Arg

key

Arg

field

Arg

value

Example

async function hIncrByExample(context: Devvit.Context) {
 await context.redis.hset("user123", { "karma": "100" });
 await context.redis.hincrby("user123", "karma", 5);
}

Inherited from

TxClientLikeBase.hIncrBy


hkeys()

hkeys(key): Promise<TxClientLike>

Parameters

key

string

Returns

Promise<TxClientLike>

Deprecated

Use TxClientLike.hKeys instead.


hKeys()

hKeys(key): Promise<TxClientLike>

Returns all field names in the hash stored at key.

Parameters

key

string

Returns

Promise<TxClientLike>

Arg

key

Example

async function hKeysExample(context: Devvit.Context) {
 await context.redis.hset("prices", {
   "chair": "48",
   "desk": "95",
   "whiteboard": "23"
 });
 const keys : string[] = await context.redis.hkeys("prices");
 console.log("Keys: " + keys);
}

Inherited from

TxClientLikeBase.hKeys


hlen()

hlen(key): Promise<TxClientLike>

Parameters

key

string

Returns

Promise<TxClientLike>

Deprecated

Use TxClientLike.hLen instead.


hLen()

hLen(key): Promise<TxClientLike>

Returns the number of fields contained in the hash stored at key.

Parameters

key

string

Returns

Promise<TxClientLike>

the number of fields in the hash, or 0 when the key does not exist.

Arg

key

Example

async function hLenExample(context: Devvit.Context) {
 await context.redis.hset("supplies", {
   "paperclips": "25",
   "pencils": "10",
   "erasers": "5",
   "pens": "7"
 });
 const numberOfFields : number = await context.redis.hlen("supplies");
 console.log("Number of fields: " + numberOfFields);
}

Inherited from

TxClientLikeBase.hLen


hMGet()

hMGet(key, fields): Promise<TxClientLike>

Returns the values associated with fields in the hash stored at key. https://redis.io/commands/hmget

Parameters

key

string

fields

string[]

Returns

Promise<TxClientLike>

values associated with each field in the order they appear in fields

Arg

key

Arg

fields

Example

async function hMGetExample(context: Devvit.Context) {
 await context.redis.hset("fruits", {"apple": "5", "orange": "7", "kiwi": "9"});
 const result : string[] | undefined = await context.redis.hmget("fruits", ["orange", "grape", "apple"]);
 console.log("Value of fields: " + result); // "Value of fields: ["7", undefined, "5"]
}

Inherited from

TxClientLikeBase.hMGet


hscan()

hscan(key, cursor, pattern?, count?): Promise<TxClientLike>

Parameters

key

string

cursor

number

pattern?

string

count?

number

Returns

Promise<TxClientLike>

Deprecated

Use TxClientLike.hScan instead.


hScan()

hScan(key, cursor, pattern?, count?): Promise<TxClientLike>

Iterates fields of Hash types and their associated values.

Parameters

key

string

cursor

number

pattern?

string

count?

number

Returns

Promise<TxClientLike>

Arg

key

Arg

cursor

Arg

pattern

Arg

count

Example

async function hScanExample(context: Devvit.Context) {
 await context.redis.hset("userInfo", {
   "name": "Bob",
   "startDate": "01-05-20",
   "totalAwards": "12"
 });

 const hScanResponse = await context.redis.hscan("userInfo", 0);

 hScanResponse.fieldValues.forEach(x => {
   console.log("Field: '" + x.field + "', Value: '" + x.value + "'");
 });
}

Inherited from

TxClientLikeBase.hScan


hset()

hset(key, fieldValues): Promise<TxClientLike>

Parameters

key

string

fieldValues

Returns

Promise<TxClientLike>

Deprecated

Use TxClientLike.hSet instead.


hSet()

hSet(key, fieldValues): Promise<TxClientLike>

Sets the specified fields to their respective values in the hash stored at key. https://redis.io/commands/hset

Parameters

key

string

fieldValues

Returns

Promise<TxClientLike>

number of fields that were added

Arg

key

Arg

fieldValues

Example

async function hSetExample(context: Devvit.Context) {
 const numFieldsAdded = await context.redis.hset("fruits", {"apple": "5", "orange": "7", "kiwi": "9"});
 console.log("Number of fields added: " + numFieldsAdded);
}

Inherited from

TxClientLikeBase.hSet


hSetNX()

hSetNX(key, field, value): Promise<TxClientLike>

Parameters

key

string

field

string

value

string

Returns

Promise<TxClientLike>

Inherited from

TxClientLikeBase.hSetNX


incrBy()

incrBy(key, value): Promise<TxClientLike>

Increments the number stored at key by increment. https://redis.io/commands/incrby/

Parameters

key

string

value

number

Returns

Promise<TxClientLike>

Arg

key

Arg

value

Example

async function incrByExample(context: Devvit.Context) {
 await context.redis.set("totalPoints", "53")
 const updatedPoints : number = await context.redis.incrby("totalPoints", 100);
 console.log("Updated points: " + updatedPoints);
}

Inherited from

TxClientLikeBase.incrBy


mget()

mget(keys): Promise<TxClientLike>

Parameters

keys

string[]

Returns

Promise<TxClientLike>

Deprecated

Use TxClientLike.mGet instead.


mGet()

mGet(keys): Promise<TxClientLike>

Returns the values of all specified keys. https://redis.io/commands/mget/

Parameters

keys

string[]

Returns

Promise<TxClientLike>

list of values at the specified keys

Arg

keys

Example

async function mGetExample(context: Devvit.Context) {
 await context.redis.mset({"name": "Zeek", "occupation": "Developer"});
 const result : (string | null)[] = await context.redis.mget(["name", "occupation"]);
 result.forEach(x => {
   console.log(x);
 });
}

Inherited from

TxClientLikeBase.mGet


mset()

mset(keyValues): Promise<TxClientLike>

Parameters

keyValues

Returns

Promise<TxClientLike>

Deprecated

Use TxClientLike.mSet instead.


mSet()

mSet(keyValues): Promise<TxClientLike>

Sets the given keys to their respective values. https://redis.io/commands/mset/

Parameters

keyValues

Returns

Promise<TxClientLike>

Arg

keyValues

Example

async function mGetExample(context: Devvit.Context) {
 await context.redis.mset({"name": "Zeek", "occupation": "Developer"});
 const result : (string | null)[] = await context.redis.mget(["name", "occupation"]);
 result.forEach(x => {
   console.log(x);
 });
}

Inherited from

TxClientLikeBase.mSet


multi()

multi(): Promise<void>

Marks the start of a transaction block. Subsequent commands will be queued for atomic execution using EXEC. https://redis.io/commands/multi/

Returns

Promise<void>

Example

async function multiExample(context: Devvit.Context) {
 await context.redis.set("karma", "32");

 const txn = await context.redis.watch("quantity");

 await txn.multi();  // Begin a transaction
 await txn.incrby("karma", 10);
 await txn.exec();   // Execute the commands in the transaction
}

Inherited from

TxClientLikeBase.multi


set()

set(key, value, options?): Promise<TxClientLike>

Set key to hold the string value. If key already holds a value, it is overwritten https://redis.io/commands/set/

Parameters

key

string

value

string

options?

SetOptions

Returns

Promise<TxClientLike>

Arg

key

Arg

value

Arg

options

Example

async function setExample(context: Devvit.Context) {
 await context.redis.set("quantity", "5");
}

Inherited from

TxClientLikeBase.set


setRange()

setRange(key, offset, value): Promise<TxClientLike>

Overwrites part of the string stored at key, starting at the specified offset, for the entire length of value. https://redis.io/commands/setrange/

Parameters

key

string

offset

number

value

string

Returns

Promise<TxClientLike>

length of the string after it was modified by the command

Arg

key

Arg

offset

Arg

value

Example

async function setRangeExample(context: Devvit.Context) {
 await context.redis.set("word", "tacocat");
 await context.redis.setrange("word", 0, "blue");
}

Inherited from

TxClientLikeBase.setRange


strlen()

strlen(key): Promise<TxClientLike>

Parameters

key

string

Returns

Promise<TxClientLike>

Deprecated

Use TxClientLike.strLen instead.


strLen()

strLen(key): Promise<TxClientLike>

Returns the length of the string value stored at key. An error is returned when key holds a non-string value. https://redis.io/commands/strlen/

Parameters

key

string

Returns

Promise<TxClientLike>

length of the string stored at key

Arg

key

Example

async function strLenExample(context: Devvit.Context) {
 await context.redis.set("word", "tacocat");
 const length : number = await context.redis.strlen("word");
 console.log("Length of word: " + length);
}

Inherited from

TxClientLikeBase.strLen


type()

type(key): Promise<TxClientLike>

Returns the string representation of the type of the value stored at key https://redis.io/commands/type/

Parameters

key

string

Returns

Promise<TxClientLike>

string representation of the type

Arg

key

Example

async function typeExample(context: Devvit.Context) {
 await context.redis.set("quantity", "5");
 const type : string = await context.redis.type("quantity");
 console.log("Key type: " + type);
}

Inherited from

TxClientLikeBase.type


unwatch()

unwatch(): Promise<TxClientLike>

Flushes all the previously watched keys for a transaction. If you call EXEC or DISCARD, there's no need to manually call UNWATCH. https://redis.io/commands/unwatch/

Returns

Promise<TxClientLike>

Example

async function unwatchExample(context: Devvit.Context) {
 await context.redis.set("gold", "50");

 const txn = await context.redis.watch("gold");

 await txn.multi();     // Begin a transaction
 await txn.incrby("gold", 30);
 await txn.unwatch();   // Unwatch "gold"

 // Now that "gold" has been unwatched, we can increment its value
 // outside the transaction without canceling the transaction
 await context.redis.incrby("gold", -20);

 await txn.exec();   // Execute the commands in the transaction

 console.log("Gold value: " + await context.redis.get("gold")); // The value of 'gold' should be 50 + 30 - 20 = 60
}

Inherited from

TxClientLikeBase.unwatch


watch()

watch(...keys): Promise<TxClientLike>

Marks the given keys to be watched for conditional execution of a transaction. https://redis.io/commands/watch/

Parameters

keys

...string[]

Returns

Promise<TxClientLike>

Arg

keys - given keys to be watched

Example

async function watchExample(context: Devvit.Context) {
 await context.redis.set("karma", "32");

 const txn = await context.redis.watch("quantity");

 await txn.multi();  // Begin a transaction
 await txn.incrby("karma", 10);
 await txn.exec();   // Execute the commands in the transaction
}

Inherited from

TxClientLikeBase.watch


zAdd()

zAdd(key, ...members): Promise<TxClientLike>

Adds all the specified members with the specified scores to the sorted set stored at key. https://redis.io/commands/zadd/

Parameters

key

string

members

...ZMember[]

Returns

Promise<TxClientLike>

number of elements added to the sorted set

Arg

key

Arg

members

Example

async function zAddExample(context: Devvit.Context) {
 const numMembersAdded : number = await context.redis.zadd("leaderboard",
   {member: "louis", score: 37},
   {member: "fernando", score: 10},
   {member: "caesar", score: 20},
   {member: "alexander", score: 25},
 );
 console.log("Number of members added: " + numMembersAdded);
}

Inherited from

TxClientLikeBase.zAdd


zCard()

zCard(key): Promise<TxClientLike>

Returns the cardinality (number of elements) of the sorted set stored at key. https://redis.io/commands/zcard/

Parameters

key

string

Returns

Promise<TxClientLike>

cardinality of the sorted set

Arg

key

Example

async function zCardExample(context: Devvit.Context) {
 await context.redis.zadd("leaderboard",
   {member: "louis", score: 37},
   {member: "fernando", score: 10},
   {member: "caesar", score: 20},
   {member: "alexander", score: 25},
 );
 const cardinality : number = await context.redis.zcard("leaderboard");
 console.log("Cardinality: " + cardinality);
}

Inherited from

TxClientLikeBase.zCard


zIncrBy()

zIncrBy(key, member, value): Promise<TxClientLike>

Increments the score of member in the sorted set stored at key by value https://redis.io/commands/zincrby/

Parameters

key

string

member

string

value

number

Returns

Promise<TxClientLike>

the new score of member as a double precision floating point number

Arg

key

Arg

member

Arg

value

Example

async function zIncrByExample(context: Devvit.Context) {
 await context.redis.zadd("animals",
   {member: "zebra", score: 92},
   {member: "cat", score: 100},
   {member: "dog", score: 95},
   {member: "elephant", score: 97}
 );
 const updatedScore : number = await context.redis.zincrby("animals", "dog", 10);
 console.log("Dog's updated score: " + updatedScore);
}

Inherited from

TxClientLikeBase.zIncrBy


zRange()

zRange(key, start, stop, options?): Promise<TxClientLike>

Returns the specified range of elements in the sorted set stored at key. https://redis.io/commands/zrange/

When using by: 'lex', the start and stop inputs will be prepended with [ by default, unless they already begin with [, ( or are one of the special values + or -.

Parameters

key

string

start

string | number

stop

string | number

options?

ZRangeOptions

Returns

Promise<TxClientLike>

list of elements in the specified range

Arg

key

Arg

start

Arg

stop

Arg

options

Example

async function zRangeExample(context: Devvit.Context) {
 await context.redis.zadd("leaderboard",
   {member: "louis", score: 37},
   {member: "fernando", score: 10},
   {member: "caesar", score: 20},
   {member: "alexander", score: 25},
 );

 // View elements with scores between 0 and 30 inclusive, sorted by score
 const scores : {member : string, score : number}[] = await context.redis.zrange("leaderboard", 0, 30, { by: "score" });

 scores.forEach(x => {
   console.log("Member: " + x.member, ", Score: " + x.score);
 });
}

Inherited from

TxClientLikeBase.zRange


zRank()

zRank(key, member): Promise<TxClientLike>

Returns the rank of member in the sorted set stored at key https://redis.io/commands/zrank/

Parameters

key

string

member

string

Returns

Promise<TxClientLike>

rank of the member. The rank (or index) is 0-based which means that the member with the lowest score has rank 0

Arg

key

Arg

member

Example

async function zRankExample(context: Devvit.Context) {
 await context.redis.zadd("animals",
   {member: "zebra", score: 92},
   {member: "cat", score: 100},
   {member: "dog", score: 95},
   {member: "elephant", score: 97}
 );
 const rank : number = await context.redis.zrank("animals", "dog");
 console.log("Dog's rank: " + rank);
}

Inherited from

TxClientLikeBase.zRank


zRem()

zRem(key, members): Promise<TxClientLike>

Removes the specified members from the sorted set stored at key. https://redis.io/commands/zrem/

Parameters

key

string

members

string[]

Returns

Promise<TxClientLike>

number of members removed from the sorted set

Arg

key

Arg

members

Example

async function zRemExample(context: Devvit.Context) {
 await context.redis.zadd("leaderboard",
   {member: "louis", score: 37},
   {member: "fernando", score: 10},
   {member: "caesar", score: 20},
   {member: "alexander", score: 25},
 );
 const numberOfMembersRemoved : number = await context.redis.zrem("leaderboard", ["fernando", "alexander"]);
 console.log("Number of members removed: " + numberOfMembersRemoved);
}

Inherited from

TxClientLikeBase.zRem


zRemRangeByLex()

zRemRangeByLex(key, min, max): Promise<TxClientLike>

removes all elements in the sorted set stored at key between the lexicographical range specified by min and max https://redis.io/commands/zremrangebylex/

Parameters

key

string

min

string

max

string

Returns

Promise<TxClientLike>

number of members removed from the sorted set

Arg

key

Arg

min

Arg

max

Example

async function zRemRangeByLexExample(context: Devvit.Context) {
 await context.redis.zadd("fruits",
   {member: "kiwi", score: 0},
   {member: "mango", score: 0},
   {member: "banana", score: 0},
   {member: "orange", score: 0},
   {member: "apple", score: 0},
 );

 // Remove fruits alphabetically ordered between 'kiwi' inclusive and 'orange' exclusive
 // Note: The symbols '[' and '(' indicate inclusive or exclusive, respectively. These must be included in the call to zremrangebylex().
 const numFieldsRemoved : number = await context.redis.zremrangebylex("fruits", "[kiwi", "(orange");
 console.log("Number of fields removed: " + numFieldsRemoved);
}

Inherited from

TxClientLikeBase.zRemRangeByLex


zRemRangeByRank()

zRemRangeByRank(key, start, stop): Promise<TxClientLike>

Removes all elements in the sorted set stored at key with rank between start and stop. https://redis.io/commands/zremrangebyrank/

Parameters

key

string

start

number

stop

number

Returns

Promise<TxClientLike>

number of members removed from the sorted set

Arg

key

Arg

start

Arg

stop

Example

async function zRemRangeByRankExample(context: Devvit.Context) {
 await context.redis.zadd("fruits",
   {member: "kiwi", score: 10},
   {member: "mango", score: 20},
   {member: "banana", score: 30},
   {member: "orange", score: 40},
   {member: "apple", score: 50},
 );

 // Remove fruits ranked 1 through 3 inclusive
 const numFieldsRemoved : number = await context.redis.zremrangebyrank("fruits", 1, 3);
 console.log("Number of fields removed: " + numFieldsRemoved);
}

Inherited from

TxClientLikeBase.zRemRangeByRank


zRemRangeByScore()

zRemRangeByScore(key, min, max): Promise<TxClientLike>

Removes all elements in the sorted set stored at key with a score between min and max https://redis.io/commands/zremrangebyscore/

Parameters

key

string

min

number

max

number

Returns

Promise<TxClientLike>

number of members removed from the sorted set

Arg

key

Arg

min

Arg

max

Example

async function zRemRangeByScoreExample(context: Devvit.Context) {
 await context.redis.zadd("fruits",
   {member: "kiwi", score: 10},
   {member: "mango", score: 20},
   {member: "banana", score: 30},
   {member: "orange", score: 40},
   {member: "apple", score: 50},
 );
 // Remove fruits scored between 30 and 50 inclusive
 const numFieldsRemoved : number = await context.redis.zremrangebyscore("fruits", 30, 50);
 console.log("Number of fields removed: " + numFieldsRemoved);
}

Inherited from

TxClientLikeBase.zRemRangeByScore


zScan()

zScan(key, cursor, pattern?, count?): Promise<TxClientLike>

Iterates elements of Sorted Set types and their associated scores.

Parameters

key

string

cursor

number

pattern?

string

count?

number

Returns

Promise<TxClientLike>

Arg

key

Arg

cursor

Arg

pattern

Arg

count

Example

async function zScanExample(context: Devvit.Context) {
 await context.redis.zadd("fruits",
   {member: "kiwi", score: 0},
   {member: "mango", score: 0},
   {member: "banana", score: 0},
   {member: "orange", score: 0},
   {member: "apple", score: 0},
 );
 const zScanResponse = await context.redis.zscan("fruits", 0);
 console.log("zScanResponse: " + JSON.stringify(zScanResponse));
}

Inherited from

TxClientLikeBase.zScan


zScore()

zScore(key, member): Promise<TxClientLike>

Returns the score of member in the sorted set at key. https://redis.io/commands/zscore/

Parameters

key

string

member

string

Returns

Promise<TxClientLike>

the score of the member (a double-precision floating point number).

Arg

key

Arg

member

Example

async function zScoreExample(context: Devvit.Context) {
 await context.redis.zadd("leaderboard",
   {member: "louis", score: 37},
   {member: "fernando", score: 10},
   {member: "caesar", score: 20},
   {member: "alexander", score: 25},
 );
 const score : number | undefined = await context.redis.zscore("leaderboard", "caesar");
 if(score !== undefined) {
   console.log("Caesar's score: " + score);
 }
}

Inherited from

TxClientLikeBase.zScore