Redis Commands Cheat Sheet

Posted : admin On 1/2/2022
Redis Commands Cheat Sheet

Skip-redis-config-generation Skip redis config generation if already specifying the common-site-config file-verbose Verbose output during install; bench -site site-name COMMAND - Specify site for command. Bench update - Pulls changes for bench-repo and all apps, applies patches, builds JS and CSS, and then migrates. Basic Redis commands - Cheat Sheet When you encounter a Redis instance and you quickly want to learn about the setup you just need a few simple commands to peak into the setup. Of course it doesn't hurt to look at the official full command documentatio n, but below is a listing just for sysadmins.

This is a super light weight reference for the interactive mode of the Redis CLI tool. I really just want to use it to explore what data is in Redis, so the emphasis is on getting in and listing data rather than setting values.

Documentation for all the Redis commands is at https://redis.io/commands

Starting the CLI in interactive mode

Connect to a locally running instance of Redis and start the interactive REPL:

Configure hints:

Get help for a command:

Query Config

List all sorts of useful config:

Select a database (key space)

Show the max number of databases this server is configured to host:

List the available databases:

Select the redis database to use:

Find out what’s in a key space

Cheat

List all the keys in the currently selected keyspace:

Batch list keys. Pass 0 the first time, then the cursor number given by Redis next time:

Query key value type

Find out what data structure a key holds:

String types

Getting, setting and removing keys holding string values:

Set types

List all members of a key holding a set data structure:

Hash types

Redis Commands Cheat Sheet

List all keys and values of a hash data structure:

List types

List all elements of a list data structure:

-1 refers to the last element of the list.

Expiring keys

If key already exists and is a string, this command appends the value at the end of the string. If key does not exist it is created and set as an empty string, so APPEND will be similar to SET in this special case.

*Return value

Integer reply: the length of the string after the append operation.

Redis Commands Cheat Sheet Roblox

*Examples

redis> EXISTS mykeyredis> APPEND mykey 'Hello'redis> APPEND mykey ' World'redis> GET mykey

*Pattern: Time series

The APPEND command can be used to create a very compact representation of a list of fixed-size samples, usually referred as time series. Every time a new sample arrives we can store it using the command

Redis Commands Cheat Sheet Fortnite

Accessing individual elements in the time series is not hard:

  • STRLEN can be used in order to obtain the number of samples.
  • GETRANGE allows for random access of elements. If our time series have associated time information we can easily implement a binary search to get range combining GETRANGE with the Lua scripting engine available in Redis 2.6.
  • SETRANGE can be used to overwrite an existing time series.

The limitation of this pattern is that we are forced into an append-only mode of operation, there is no way to cut the time series to a given size easily because Redis currently lacks a command able to trim string objects. However the space efficiency of time series stored in this way is remarkable.

Hint: it is possible to switch to a different key based on the current Unix time, in this way it is possible to have just a relatively small amount of samples per key, to avoid dealing with very big keys, and to make this pattern more friendly to be distributed across many Redis instances.

An example sampling the temperature of a sensor using fixed-size strings (using a binary format is better in real implementations).

Commands
redis> APPEND ts '0043'redis> APPEND ts '0035'redis> GETRANGE ts 0 3redis> GETRANGE ts 4 7

Related commands