### Start Redis Server Source: https://github.com/redis/redis-doc/blob/master/docs/install/install-redis/install-redis-on-windows.md Starts the Redis server process. This command assumes Redis has been installed via the APT repository. ```bash sudo service redis-server start ``` -------------------------------- ### Install go-redis Source: https://github.com/redis/redis-doc/blob/master/docs/connect/clients/go.md Install the go-redis/v9 package using go get. ```bash go get github.com/redis/go-redis/v9 ``` -------------------------------- ### GET command output example Source: https://github.com/redis/redis-doc/blob/master/commands/command.md Example output for the GET command, detailing its flags, ACL categories, and key specifications. ```redis-cli 1) 1) "get" 2) (integer) 2 3) 1) readonly 2) fast 4) (integer) 1 5) (integer) 1 6) (integer) 1 7) 1) "@read" 2) "@string" 3) "@fast" 8) (empty array) 9) 1) 1) "flags" 2) 1) read 3) "begin_search" 4) 1) "type" 2) "index" 3) "spec" 4) 1) "index" 2) (integer) 1 5) "find_keys" 6) 1) "type" 2) "range" 3) "spec" 4) 1) "lastkey" 2) (integer) 0 3) "keystep" 4) (integer) 1 5) "limit" 6) (integer) 0 10) (empty array) ... ``` -------------------------------- ### ASCII Diagram: Two-Sentinel Setup Source: https://github.com/redis/redis-doc/blob/master/docs/management/sentinel.md Example of a two-Sentinel deployment configuration. ```text +----+ +----+ | M1 |---------| R1 | | S1 | | S2 | +----+ +----+ Configuration: quorum = 1 ``` -------------------------------- ### Install and configure Docker on Amazon Linux Source: https://github.com/redis/redis-doc/blob/master/docs/install/install-redisinsight/install-on-aws.md Commands to update the system, install Docker, start the service, and configure user permissions. ```bash sudo yum update -y sudo yum install -y docker sudo service docker start sudo usermod -a -G docker ec2-user docker ps ``` -------------------------------- ### Basic ZRANGEBYSCORE Examples Source: https://github.com/redis/redis-doc/blob/master/commands/zrangebyscore.md Illustrates basic usage of ZRANGEBYSCORE with different score ranges and the ZADD command for setup. ```cli ZADD myzset 1 "one" ZADD myzset 2 "two" ZADD myzset 3 "three" ZRANGEBYSCORE myzset -inf +inf ZRANGEBYSCORE myzset 1 2 ZRANGEBYSCORE myzset (1 2 ZRANGEBYSCORE myzset (1 (2 ``` -------------------------------- ### Set and Get Bit Example Source: https://github.com/redis/redis-doc/blob/master/docs/data-types/bitmaps.md Demonstrates setting a bit to 1 at a specific offset and then retrieving its value. Also shows retrieving a bit that has not been set, which defaults to 0. ```redis SETBIT pings:2024-01-01-00:00 123 1 ``` ```redis GETBIT pings:2024-01-01-00:00 123 ``` ```redis GETBIT pings:2024-01-01-00:00 456 ``` -------------------------------- ### Command Permission Examples Source: https://github.com/redis/redis-doc/blob/master/docs/management/security/acl.md Examples of how specific commands map to read and write permission requirements. ```text LPUSH key1 data ``` ```text LPOP key2 ``` -------------------------------- ### Start Redis Instance Source: https://github.com/redis/redis-doc/blob/master/docs/install/install-redis/_index.md Starts the Redis instance using the configured init script. This command requires superuser privileges. ```bash sudo /etc/init.d/redis_6379 start ``` -------------------------------- ### Start Redis with Command-Line Arguments Source: https://github.com/redis/redis-doc/blob/master/docs/management/config.md Starts a Redis instance on a specific port and configures it as a replica using command-line arguments. ```bash ./redis-server --port 6380 --replicaof 127.0.0.1 6379 ``` -------------------------------- ### Redis HELP Command Output Example Source: https://github.com/redis/redis-doc/blob/master/docs/connect/cli.md Example output of the HELP command for PFADD, showing its syntax, summary, and the Redis version it was introduced in. ```text PFADD key element [element ...] summary: Adds the specified elements to the specified HyperLogLog. since: 2.8.9 ``` -------------------------------- ### Get Configuration On-the-Fly Source: https://github.com/redis/redis-doc/blob/master/docs/management/config.md Example of using the CONFIG GET command to retrieve Redis configuration values while the server is running. ```redis-cli CONFIG GET max-replication-lag ``` -------------------------------- ### Get Help for a Specific Redis Command Source: https://github.com/redis/redis-doc/blob/master/docs/connect/cli.md Displays detailed help information for a specific Redis command. This example shows how to get help for the PFADD command. ```shell 127.0.0.1:6379> HELP PFADD ``` -------------------------------- ### MSET command output example Source: https://github.com/redis/redis-doc/blob/master/commands/command.md Example output for the MSET command, showing its metadata including first key, last key, and step. ```redis-cli 1) 1) "mset" 2) (integer) -3 3) 1) write 2) denyoom 4) (integer) 1 5) (integer) -1 6) (integer) 2 ... ``` -------------------------------- ### Redis Max Clients Configuration Example Source: https://github.com/redis/redis-doc/blob/master/docs/reference/clients.md This example shows how to configure the maximum number of clients Redis can handle using the --maxclients command-line argument. It also demonstrates the log message Redis displays when the requested limit exceeds the system's capabilities. ```bash $ ./redis-server --maxclients 100000 [41422] 23 Jan 11:28:33.179 # Unable to set the max number of files limit to 100032 (Invalid argument), setting the max clients configuration to 10112. ``` -------------------------------- ### Example: Reporting Key Positions Source: https://github.com/redis/redis-doc/blob/master/docs/reference/modules/modules-api-ref.md An example demonstrating how to use RedisModule_IsKeysPositionRequest and RedisModule_KeyAtPosWithFlags to report key positions and their access types within a module command. ```c if (RedisModule_IsKeysPositionRequest(ctx)) { RedisModule_KeyAtPosWithFlags(ctx, 2, REDISMODULE_CMD_KEY_RO | REDISMODULE_CMD_KEY_ACCESS); RedisModule_KeyAtPosWithFlags(ctx, 1, REDISMODULE_CMD_KEY_RW | REDISMODULE_CMD_KEY_UPDATE | REDISMODULE_CMD_KEY_ACCESS); } ``` -------------------------------- ### Install redis-py Source: https://github.com/redis/redis-doc/blob/master/docs/connect/clients/python.md Install the redis-py library using pip. For enhanced performance, consider installing with hiredis support. ```bash pip install redis ``` ```bash pip install redis[hiredis] ``` -------------------------------- ### Example: Implement a Blocking Command Source: https://github.com/redis/redis-doc/blob/master/docs/reference/modules/modules-blocking-ops.md This example shows a command that blocks the client for one second using a separate thread before unblocking it. It demonstrates the basic structure of initiating a block and resuming. ```c int Example_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { RedisModuleBlockedClient *bc = RedisModule_BlockClient(ctx,reply_func,timeout_func,NULL,0); pthread_t tid; pthread_create(&tid,NULL,threadmain,bc); return REDISMODULE_OK; } ``` ```c void *threadmain(void *arg) { RedisModuleBlockedClient *bc = arg; sleep(1); /* Wait one second and unblock. */ RedisModule_UnblockClient(bc,NULL); } ``` -------------------------------- ### Install Redis from Snapcraft Source: https://github.com/redis/redis-doc/blob/master/docs/install/install-redis/install-redis-on-linux.md Installs the Redis package using Snapcraft. This method is suitable for Linux distributions that support snap. ```bash sudo snap install redis ``` -------------------------------- ### SORT command output example Source: https://github.com/redis/redis-doc/blob/master/commands/command.md Example output for the SORT command, illustrating the structure that indicates movable keys. ```redis-cli 1) 1) "sort" 2) (integer) -2 3) 1) write 2) denyoom 3) movablekeys 4) (integer) 1 5) (integer) 1 6) (integer) 1 ... ``` -------------------------------- ### Example Redis Configuration Directive Source: https://github.com/redis/redis-doc/blob/master/docs/management/config.md A basic example of a configuration directive in redis.conf. ```redis-conf replicaof 127.0.0.1 6380 ``` -------------------------------- ### Add Redis APT repository and install Redis on Ubuntu/Debian Source: https://github.com/redis/redis-doc/blob/master/docs/install/install-redis/install-redis-on-linux.md Adds the official Redis APT repository, updates the package index, and installs the Redis server. Ensure you have curl and gpg installed. ```bash curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list sudo apt-get update sudo apt-get install redis ``` -------------------------------- ### MGET command output example Source: https://github.com/redis/redis-doc/blob/master/commands/command.md Example output for the MGET command, showing its metadata including first key, last key, and step. ```redis-cli 1) 1) "mget" 2) (integer) -2 3) 1) readonly 2) fast 4) (integer) 1 5) (integer) -1 6) (integer) 1 ... ``` -------------------------------- ### Check Homebrew Version Source: https://github.com/redis/redis-doc/blob/master/docs/install/install-redis/install-redis-on-mac-os.md Verify if Homebrew is installed on your system. If this command fails, Homebrew needs to be installed. ```bash brew --version ``` -------------------------------- ### Install prerequisites for Redis on Ubuntu/Debian Source: https://github.com/redis/redis-doc/blob/master/docs/install/install-redis/install-redis-on-linux.md Install lsb-release, curl, and gpg if running a minimal distribution. These are required for adding the Redis APT repository. ```bash sudo apt install lsb-release curl gpg ``` -------------------------------- ### Install Redis binaries Source: https://github.com/redis/redis-doc/blob/master/docs/install/install-redis/install-redis-from-source.md Copies the compiled Redis binaries to /usr/local/bin. ```bash sudo make install ``` -------------------------------- ### Example Usage Source: https://github.com/redis/redis-doc/blob/master/commands/xtrim.md Demonstrates adding entries to a stream and then trimming it. ```APIDOC ## Example Usage This example shows how to add multiple fields to a stream and then trim it to keep only the latest 2 entries. ### Add entries to a stream ```cli XADD mystream * field1 A field2 B field3 C field4 D ``` ### Trim the stream to the latest 2 entries ```cli XTRIM mystream MAXLEN 2 ``` ### Retrieve all entries from the stream to verify ```cli XRANGE mystream - + ``` ``` -------------------------------- ### Start Redis Service using launchd Source: https://github.com/redis/redis-doc/blob/master/docs/install/install-redis/install-redis-on-mac-os.md Use Homebrew services to start Redis in the background. This configuration ensures Redis restarts automatically at login. ```bash brew services start redis ``` -------------------------------- ### Redis Wire Protocol Example: Subscribe Source: https://github.com/redis/redis-doc/blob/master/docs/interact/pubsub.md This example demonstrates the wire protocol for subscribing to channels. It shows the initial SUBSCRIBE command and the subsequent 'subscribe' replies from the server, indicating successful subscription and the current number of subscribed channels. ```text SUBSCRIBE first second *3 $9 subscribe $5 first :1 *3 $9 subscribe $6 second :2 ``` -------------------------------- ### Redis Wire Protocol Example: Publish and Message Source: https://github.com/redis/redis-doc/blob/master/docs/interact/pubsub.md This example illustrates the wire protocol for publishing a message and the subsequent 'message' reply received by subscribers. It shows a PUBLISH command and the resulting message format, including the message type, channel, and payload. ```text > PUBLISH second Hello *3 $7 message $6 second $5 Hello ``` -------------------------------- ### ZMPOP Usage Examples Source: https://github.com/redis/redis-doc/blob/master/commands/zmpop.md Demonstrates popping elements from sorted sets using various MIN, MAX, and COUNT configurations. ```cli ZMPOP 1 notsuchkey MIN ZADD myzset 1 "one" 2 "two" 3 "three" ZMPOP 1 myzset MIN ZRANGE myzset 0 -1 WITHSCORES ZMPOP 1 myzset MAX COUNT 10 ZADD myzset2 4 "four" 5 "five" 6 "six" ZMPOP 2 myzset myzset2 MIN COUNT 10 ZRANGE myzset 0 -1 WITHSCORES ZMPOP 2 myzset myzset2 MAX COUNT 10 ZRANGE myzset2 0 -1 WITHSCORES EXISTS myzset myzset2 ``` -------------------------------- ### Start Redis server Source: https://github.com/redis/redis-doc/blob/master/docs/install/install-redis/install-redis-from-source.md Launches the Redis server process in the foreground. ```bash redis-server ``` -------------------------------- ### HELLO Command - With Authentication and Client Name Source: https://github.com/redis/redis-doc/blob/master/commands/hello.md Example of the HELLO command used to switch protocol, authenticate, and set a client name. ```APIDOC ## HELLO protover AUTH SETNAME ### Description Switches the connection protocol, authenticates the client, and sets a custom client name in a single command. ### Method `HELLO` ### Endpoint N/A (Command-line interface) ### Parameters #### Query Parameters - **protover** (integer) - Optional - Specifies the protocol version to switch to (e.g., '2' or '3'). Defaults to RESP2 if not provided. - **AUTH** (string, string) - Optional - Username and password for authentication. Use 'default' for username if using `requirepass`. - **SETNAME** (string) - Optional - The desired name for the client connection. ### Request Example ```redis HELLO 3 AUTH default mypassword SETNAME my-client-connection ``` ### Response #### Success Response (200) Returns server and connection properties, similar to the basic HELLO command, confirming the protocol switch, authentication, and client name setting. #### Response Example ```json { "server" => "redis", "version" => "7.0.0", "proto" => (integer) 3, "id" => (integer) 15, "mode" => "standalone", "role" => "master", "modules" => (empty array) } ``` ``` -------------------------------- ### Start a Redis Instance Source: https://github.com/redis/redis-doc/blob/master/docs/management/scaling.md Command to launch a Redis server instance using a specific configuration file. ```bash cd 7000 redis-server ./redis.conf ``` -------------------------------- ### HELLO Command - Switch to RESP3 Source: https://github.com/redis/redis-doc/blob/master/commands/hello.md Example of the HELLO command used to switch the connection protocol to RESP3. ```APIDOC ## HELLO protover 3 ### Description Switches the connection protocol to RESP3 and returns server and connection properties. ### Method `HELLO` ### Endpoint N/A (Command-line interface) ### Parameters #### Query Parameters - **protover** (integer) - Required - Specifies the protocol version to switch to. Use '3' for RESP3. ### Request Example ```redis HELLO 3 ``` ### Response #### Success Response (200) - **server** (string) - The server type. - **version** (string) - The Redis server version. - **proto** (integer) - The protocol version (will be 3). - **id** (integer) - The client ID. - **mode** (string) - The connection mode (e.g., standalone). - **role** (string) - The replication role (e.g., master). - **modules** (array) - List of loaded modules. #### Response Example ```json { "server" => "redis", "version" => "6.0.0", "proto" => (integer) 3, "id" => (integer) 10, "mode" => "standalone", "role" => "master", "modules" => (empty array) } ``` ``` -------------------------------- ### BLPOP command usage example Source: https://github.com/redis/redis-doc/blob/master/commands/blpop.md Demonstrates basic usage of BLPOP to retrieve elements from a list. ```redis redis> DEL list1 list2 (integer) 0 redis> RPUSH list1 a b c (integer) 3 redis> BLPOP list1 list2 0 1) "list1" 2) "a" ``` -------------------------------- ### Increment and Get Bitfield Values Source: https://github.com/redis/redis-doc/blob/master/commands/bitfield.md This example demonstrates incrementing a signed 5-bit integer and getting an unsigned 4-bit integer from a Redis string. The key is automatically created or expanded if it doesn't exist. ```redis BITFIELD mykey INCRBY i5 100 1 GET u4 0 ``` -------------------------------- ### Get Substring with Positive Offsets Source: https://github.com/redis/redis-doc/blob/master/commands/getrange.md Use GETRANGE with start and end offsets to extract a substring. Offsets are inclusive. ```cli SET mykey "This is a string" GETRANGE mykey 0 3 ``` -------------------------------- ### Read Entries from a Redis Stream Source: https://github.com/redis/redis-doc/blob/master/docs/data-types/streams.md Use XRANGE to retrieve a range of entries from a stream. Specify the start and end IDs, and optionally a COUNT to limit the number of entries returned. This example reads two entries starting from a specific ID. ```redis > XRANGE race:france 1692632086370-0 + COUNT 2 1) 1) "1692632086370-0" 2) 1) "rider" 2) "Castilla" 3) "speed" 4) "30.2" 5) "position" 6) "1" 7) "location_id" 8) "1" 2) 1) "1692632094485-0" 2) 1) "rider" 2) "Norem" 3) "speed" 4) "28.8" 5) "position" 6) "3" 7) "location_id" 8) "1" ``` -------------------------------- ### Retrieve entries from a Redis stream Source: https://github.com/redis/redis-doc/blob/master/commands/xdel.md Use XRANGE to get a range of entries from a stream. This example shows entries after one has been deleted. ```redis 127.0.0.1:6379> XRANGE mystream - + 1) 1) 1538561698944-0 2) 1) "a" 2) "1" 2) 1) 1538561701744-0 2) 1) "c" 2) "3" ``` -------------------------------- ### Get Default XINFO STREAM Reply Source: https://github.com/redis/redis-doc/blob/master/commands/xinfo-stream.md Use this command to retrieve basic information about a Redis stream. No special setup is required. ```redis > XINFO STREAM mystream ``` -------------------------------- ### Sentinel Monitor Event Log Source: https://github.com/redis/redis-doc/blob/master/docs/management/sentinel.md An example log message from a Sentinel instance indicating that it has started monitoring a master. This event can also be received via Pub/Sub. ```text +monitor master mymaster 127.0.0.1 6379 quorum 2 ``` -------------------------------- ### Example Usage of RPOPLPUSH Source: https://github.com/redis/redis-doc/blob/master/commands/rpoplpush.md Demonstrates the basic usage of RPOPLPUSH with RPUSH, LRANGE. ```cli RPUSH mylist "one" RPUSH mylist "two" RPUSH mylist "three" RPOPLPUSH mylist myotherlist LRANGE mylist 0 -1 LRANGE myotherlist 0 -1 ``` -------------------------------- ### Initialize Go module Source: https://github.com/redis/redis-doc/blob/master/docs/connect/clients/go.md Initialize a new Go module before installing dependencies. ```bash go mod init github.com/my/repo ``` -------------------------------- ### Get Redis Data Type Source: https://github.com/redis/redis-doc/blob/master/commands/type.md Use the TYPE command to determine the data type of a key. Examples show setting different types and then checking their types. ```cli SET key1 "value" LPUSH key2 "value" SADD key3 "value" TYPE key1 TYPE key2 TYPE key3 ``` -------------------------------- ### HELLO Command (Switch to RESP3) Source: https://github.com/redis/redis-doc/blob/master/commands/hello.md Clients can initiate a handshake using the RESP3 protocol by calling HELLO with '3' as the protover argument. The response includes updated server and connection details. ```redis > HELLO 3 1# "server" => "redis" 2# "version" => "6.0.0" 3# "proto" => (integer) 3 4# "id" => (integer) 10 5# "mode" => "standalone" 6# "role" => "master" 7# "modules" => (empty array) ``` -------------------------------- ### String Configuration Get Callback Example Source: https://github.com/redis/redis-doc/blob/master/docs/reference/modules/modules-api-ref.md Implement a `getfn` callback to retrieve the current string configuration value from the module. The returned RedisModuleString is not consumed and remains valid after execution. ```c RedisModuleString *getStringConfigCommand(const char *name, void *privdata) { return strval; } ``` -------------------------------- ### Basic SETNX Usage Source: https://github.com/redis/redis-doc/blob/master/commands/setnx.md Demonstrates the basic usage of SETNX to set a key if it doesn't exist, and how subsequent attempts to set the same key fail. Includes a GET command to show the final value. ```cli SETNX mykey "Hello" SETNX mykey "World" GET mykey ``` -------------------------------- ### Manage Bike Metrics with Bitfields Source: https://github.com/redis/redis-doc/blob/master/docs/data-types/bitfields.md Use BITFIELD to set, increment, and get unsigned 32-bit integer values for bike price and owner count. Initial setup, updates, and final retrieval are demonstrated. ```redis BITFIELD bike:1:stats SET u32 #0 1000 ``` ```redis BITFIELD bike:1:stats INCRBY u32 #0 -50 INCRBY u32 #1 1 ``` ```redis BITFIELD bike:1:stats INCRBY u32 #0 500 INCRBY u32 #1 1 ``` ```redis BITFIELD bike:1:stats GET u32 #0 GET u32 #1 ``` -------------------------------- ### Perform BITOP AND operation Source: https://github.com/redis/redis-doc/blob/master/commands/bitop.md This example demonstrates how to use BITOP with the AND operation on two keys and retrieve the result. Ensure keys contain string values. ```cli SET key1 "foobar" SET key2 "abcdef" BITOP AND dest key1 key2 GET dest ``` -------------------------------- ### Start Redis Stream Iterator Source: https://github.com/redis/redis-doc/blob/master/docs/reference/modules/modules-api-ref.md Sets up a stream iterator. Use flags to control range inclusion and iteration order. Pass NULL for start/end to iterate the entire stream. Error handling is omitted in the example. ```c int RedisModule_StreamIteratorStart(RedisModuleKey *key, int flags, RedisModuleStreamID *start, RedisModuleStreamID *end); ``` ```c RedisModule_StreamIteratorStart(key, 0, startid_ptr, endid_ptr); RedisModuleStreamID id; long numfields; while (RedisModule_StreamIteratorNextID(key, &id, &numfields) == REDISMODULE_OK) { RedisModuleString *field, *value; while (RedisModule_StreamIteratorNextField(key, &field, &value) == REDISMODULE_OK) { // // ... Do stuff ... // RedisModule_FreeString(ctx, field); RedisModule_FreeString(ctx, value); } } RedisModule_StreamIteratorStop(key); ``` -------------------------------- ### Execute BLPOP with multiple keys Source: https://github.com/redis/redis-doc/blob/master/commands/blpop.md Demonstrates the syntax for checking multiple keys in order for a non-empty list. ```text BLPOP list1 list2 list3 0 ``` -------------------------------- ### Basic SCAN Iteration Example Source: https://github.com/redis/redis-doc/blob/master/commands/scan.md Demonstrates starting a SCAN iteration with cursor 0 and continuing until the cursor returns to 0, signaling completion. The returned value is a two-element array: the new cursor and a list of elements. ```redis redis 127.0.0.1:6379> scan 0 1) "17" 2) 1) "key:12" 2) "key:8" 3) "key:4" 4) "key:14" 5) "key:16" 6) "key:17" 7) "key:15" 8) "key:10" 9) "key:3" 10) "key:7" 11) "key:1" redis 127.0.0.1:6379> scan 17 1) "0" 2) 1) "key:5" 2) "key:18" 3) "key:0" 4) "key:2" 5) "key:19" 6) "key:13" 7) "key:6" 8) "key:9" 9) "key:11" ``` -------------------------------- ### Set and Get ACL User Configuration Source: https://github.com/redis/redis-doc/blob/master/commands/acl-getuser.md Example of setting up an ACL user with various permissions and then retrieving the configuration using ACL GETUSER. Note the output format changes for keys and channels in version 7.0+. ```redis > ACL SETUSER sample on nopass +GET allkeys &* (+SET ~key2) "OK" ``` ```redis > ACL GETUSER sample 1) "flags" 2) 1) "on" 2) "allkeys" 3) "nopass" 3) "passwords" 4) (empty array) 5) "commands" 6) "+@all" 7) "keys" 8) "~*" 9) "channels" 10) "&*" 11) "selectors" 12) 1) 1) "commands" 6) "+SET" 7) "keys" 8) "~key2" 9) "channels" 10) "&*" ``` -------------------------------- ### Redis SDIFF Example Source: https://github.com/redis/redis-doc/blob/master/commands/sdiff.md Demonstrates the SDIFF command with sample set data. Keys that do not exist are considered empty sets. ```redis key1 = {a,b,c,d} key2 = {c} key3 = {a,c,e} SDIFF key1 key2 key3 = {b,d} ``` -------------------------------- ### Get Field Value from Redis Hash Source: https://github.com/redis/redis-doc/blob/master/commands/hget.md Use HGET to retrieve the value of a field from a hash. If the field does not exist, it returns nil. The example first sets a field and then retrieves it, also showing retrieval of a non-existent field. ```cli HSET myhash field1 "foo" HGET myhash field1 HGET myhash field2 ``` -------------------------------- ### Retrieve elements within a lexicographical range (inclusive start, exclusive end) Source: https://github.com/redis/redis-doc/blob/master/commands/zrangebylex.md Use ZRANGEBYLEX to get elements from the sorted set 'myzset' where the value is greater than or equal to '-' and less than '(c'. This command is effective when all elements share the same score. ```cli ZRANGEBYLEX myzset - (c ``` -------------------------------- ### Connect to Redis Source: https://github.com/redis/redis-doc/blob/master/docs/connect/clients/nodejs.md Basic connection setup for a local Redis instance. ```javascript import { createClient } from 'redis'; const client = createClient(); client.on('error', err => console.log('Redis Client Error', err)); await client.connect(); ``` -------------------------------- ### Retrieve elements within a lexicographical range (inclusive start, exclusive end) Source: https://github.com/redis/redis-doc/blob/master/commands/zrangebylex.md Use ZRANGEBYLEX to get elements from the sorted set 'myzset' where the value is greater than or equal to '-' and less than 'c'. This command is effective when all elements share the same score. ```cli ZRANGEBYLEX myzset - [c ``` -------------------------------- ### Prepare Local Cluster Directories Source: https://github.com/redis/redis-doc/blob/master/docs/management/scaling.md Commands to create a directory structure for testing a multi-node cluster locally. ```bash mkdir cluster-test cd cluster-test mkdir 7000 7001 7002 7003 7004 7005 ``` -------------------------------- ### Get Redis Configuration Parameters Source: https://github.com/redis/redis-doc/blob/master/commands/config-get.md Use `CONFIG GET` with glob-style patterns to retrieve specific configuration parameters. To get all parameters, use `CONFIG GET *`. ```redis redis> config get *max-*-entries* maxmemory 1) "maxmemory" 2) "0" 3) "hash-max-listpack-entries" 4) "512" 5) "hash-max-ziplist-entries" 6) "512" 7) "set-max-intset-entries" 8) "512" 9) "zset-max-listpack-entries" 10) "128" 11) "zset-max-ziplist-entries" 12) "128" ``` -------------------------------- ### Configure connection options Source: https://github.com/redis/redis-doc/blob/master/docs/connect/cli.md Connect to a specific host, port, password, or database using command line flags. ```bash $ redis-cli -h redis15.localnet.org -p 6390 PING PONG ``` ```bash $ redis-cli -a myUnguessablePazzzzzword123 PING PONG ``` ```bash $ redis-cli FLUSHALL OK $ redis-cli -n 1 INCR a (integer) 1 $ redis-cli -n 1 INCR a (integer) 2 $ redis-cli -n 2 INCR a (integer) 1 ``` ```bash $ redis-cli -u redis://LJenkins:p%40ssw0rd@redis-16379.hosted.com:16379/0 PING PONG ``` -------------------------------- ### Retrieve Entries with Exclusive Start ID Source: https://github.com/redis/redis-doc/blob/master/commands/xrange.md Use the '(' prefix on an ID to specify an exclusive start interval. This is useful for iterating streams, ensuring the starting entry itself is not included. ```redis > XRANGE writers (1526985685298-0 + COUNT 2 1) 1) 1526985691746-0 2) 1) "name" 2) "Toni" 3) "surname" 4) "Morrison" 2) 1) 1526985712947-0 2) 1) "name" 2) "Agatha" 3) "surname" 4) "Christie" ``` -------------------------------- ### Install node-redis Source: https://github.com/redis/redis-doc/blob/master/docs/connect/clients/nodejs.md Command to install the node-redis package via npm. ```bash npm install redis ``` -------------------------------- ### Basic GETSET Usage Source: https://github.com/redis/redis-doc/blob/master/commands/getset.md Shows the basic operation of setting a new value and retrieving the previous one. ```cli SET mykey "Hello" GETSET mykey "World" GET mykey ``` -------------------------------- ### BITPOS command usage examples Source: https://github.com/redis/redis-doc/blob/master/commands/bitpos.md Demonstrates finding bit positions with various byte and bit-based range configurations. ```cli SET mykey "\xff\xf0\x00" BITPOS mykey 0 SET mykey "\x00\xff\xf0" BITPOS mykey 1 0 BITPOS mykey 1 2 BITPOS mykey 1 2 -1 BYTE BITPOS mykey 1 7 15 BIT set mykey "\x00\x00\x00" BITPOS mykey 1 BITPOS mykey 1 7 -3 BIT ``` -------------------------------- ### SENTINEL CONFIG GET Source: https://github.com/redis/redis-doc/blob/master/docs/management/sentinel.md Get the current value of a global Sentinel configuration parameter. ```APIDOC ## SENTINEL CONFIG GET ### Description Get the current value of a global Sentinel configuration parameter. The specified name may be a wildcard. ### Parameters #### Request Body - **name** (string) - Required - The configuration parameter name or wildcard. ``` -------------------------------- ### Install spellchecker-cli globally Source: https://github.com/redis/redis-doc/blob/master/README.md Use npm to install the spellchecker-cli package on your local machine. ```bash npm install --global spellchecker-cli ``` -------------------------------- ### Stream Operations Example Source: https://github.com/redis/redis-doc/blob/master/commands/xrange.md Demonstrates adding entries to a stream, checking its length, and performing a range query. ```cli XADD writers * name Virginia surname Woolf XADD writers * name Jane surname Austen XADD writers * name Toni surname Morrison XADD writers * name Agatha surname Christie XADD writers * name Ngozi surname Adichie XLEN writers XRANGE writers - + COUNT 2 ``` -------------------------------- ### Retrieve command information Source: https://github.com/redis/redis-doc/blob/master/docs/reference/command-tips.md Example output showing the response_policy tip within the command info metadata. ```redis redis> command info ping 1) 1) "ping" 2) (integer) -1 3) 1) fast 4) (integer) 0 5) (integer) 0 6) (integer) 0 7) 1) @fast 2) @connection 8) 1) "request_policy:all_shards" 2) "response_policy:all_succeeded" 9) (empty array) 10) (empty array) ``` -------------------------------- ### JSON to RESP Map Example Source: https://github.com/redis/redis-doc/blob/master/docs/reference/protocol-spec.md An example showing how a JSON object is represented in the RESP map format. ```json { "first": 1, "second": 2 } ``` ```text %2\r\n +first\r\n :1\r\n +second\r\n :2\r\n ``` -------------------------------- ### Retrieve values using Redis CLI Source: https://github.com/redis/redis-doc/blob/master/commands/get.md Demonstrates basic usage of GET for non-existent and existing keys. ```cli GET nonexisting SET mykey "Hello" GET mykey ``` -------------------------------- ### Install Redis using Homebrew Source: https://github.com/redis/redis-doc/blob/master/docs/install/install-redis/install-redis-on-mac-os.md Install the Redis package on your macOS system using the Homebrew package manager. ```bash brew install redis ``` -------------------------------- ### Perform SDIFFSTORE and Display Result Source: https://github.com/redis/redis-doc/blob/master/commands/sdiffstore.md Use SDIFFSTORE to compute the difference between key1 and key2 and store it in key. Then use SMEMBERS to view the contents of the resulting set. ```cli SADD key1 "a" SADD key1 "b" SADD key1 "c" SADD key2 "c" SADD key2 "d" SADD key2 "e" SDIFFSTORE key key1 key2 SMEMBERS key ``` -------------------------------- ### View XINFO Help Documentation Source: https://github.com/redis/redis-doc/blob/master/docs/data-types/streams.md Displays the available subcommands and syntax for the XINFO command. ```text > XINFO HELP 1) XINFO [ [value] [opt] ...]. Subcommands are: 2) CONSUMERS 3) Show consumers of . 4) GROUPS 5) Show the stream consumer groups. 6) STREAM [FULL [COUNT ] 7) Show information about the stream. 8) HELP 9) Prints this help. ```