Documentation Index
Fetch the complete documentation index at: https://mintlify.com/upstash/redis-js/llms.txt
Use this file to discover all available pages before exploring further.
Returns the cardinality (number of elements) of the set stored at key.
Usage
Parameters
Response
The cardinality (number of members) of the set, or 0 if the key does not exist
Examples
Get set size
await redis.sadd("myset", "hello", "world", "foo");
const size = await redis.scard("myset");
console.log(size); // 3
Get size of empty set
const size = await redis.scard("nonexistent");
console.log(size); // 0
Track active sessions
await redis.sadd("sessions:active", "session1", "session2", "session3");
const activeCount = await redis.scard("sessions:active");
console.log(`Active sessions: ${activeCount}`); // Active sessions: 3
Monitor set size changes
await redis.sadd("tags", "javascript", "typescript");
console.log(await redis.scard("tags")); // 2
await redis.sadd("tags", "python", "go");
console.log(await redis.scard("tags")); // 4
await redis.srem("tags", "javascript");
console.log(await redis.scard("tags")); // 3