DEV Community

Cover image for ##Redis Rapid Reference: Mastering All Commands with PowerShell ๐Ÿš€๐Ÿ’กโœจ๐Ÿ”ฎ
Shubham Srivastava
Shubham Srivastava

Posted on

##Redis Rapid Reference: Mastering All Commands with PowerShell ๐Ÿš€๐Ÿ’กโœจ๐Ÿ”ฎ

Redis Documentation

Welcome to the Redis documentation! Redis is an open-source, in-memory data structure store used as a database, cache, and message broker. It supports various data structures such as:

  • Strings
  • Hashes
  • Lists
  • Sets
  • Sorted sets
  • Bitmaps
  • Hyperloglogs
  • Geospatial indexes with radius queries

In this documentation, we'll cover basic commands and functionalities of Redis using the provided PowerShell commands. ๐Ÿš€๐Ÿ’ก

Getting Started

First, make sure you have Docker installed on your system to run Redis in a containerized environment.

Install Docker

Follow the instructions on the official Docker website to install Docker on your system: https://docs.docker.com/get-docker/

Table of Contents

  1. Introduction to Redis ๐ŸŒŸ
  2. SET and GET Commands ๐Ÿ”ง
  3. SETNX Command ๐Ÿ›ก๏ธ
  4. MSET and MGET Commands ๐Ÿš€
  5. LPUSH and LPOP Commands ๐Ÿ”„
  6. SADD Command โž•
  7. ZADD and ZRANGE Commands ๐Ÿ“Š
  8. HSET Command ๐Ÿท๏ธ
  9. PUBLISH Command ๐Ÿ“ข
  10. SUBSCRIBE Command ๐Ÿ“ก

Introduction to Redis

Redis is a powerful, open-source, in-memory data structure store known for its performance and versatility. It supports various data structures like strings, hashes, lists, sets, and more, making it ideal for caching, real-time analytics, messaging queues, and much more.

SET and GET Commands

  • SET: Set a key to hold a string value.
  127.0.0.1:6379> SET name shubham
  OK
Enter fullscreen mode Exit fullscreen mode
  • GET: Get the value of a key.
  127.0.0.1:6379> GET name
  "shubham"
Enter fullscreen mode Exit fullscreen mode

SETNX Command

  • SETNX: Set the value of a key, only if the key does not exist.
  127.0.0.1:6379> SETNX user:4 Ayush NX
  OK
Enter fullscreen mode Exit fullscreen mode

MSET and MGET Commands

  • MSET: Set multiple keys to multiple values in a single atomic operation.
  • MGET: Retrieve the values of multiple keys.
  127.0.0.1:6379> MSET id:1 "hey" id:2 "hello"
  OK
  127.0.0.1:6379> MGET id:1 id:2
  1) "hey"
  2) "hello"
Enter fullscreen mode Exit fullscreen mode

LPUSH and LPOP Commands

  • LPUSH: Add one or more values to the beginning of a list.
  • LPOP: Remove and return the first element of a list.
  127.0.0.1:6379> LPUSH messages hey
  (integer) 1
  127.0.0.1:6379> LPOP messages
  "hey"
Enter fullscreen mode Exit fullscreen mode

SADD Command

  • SADD: Add one or more members to a set.
  127.0.0.1:6379> SADD ip 1
  (integer) 1
Enter fullscreen mode Exit fullscreen mode

ZADD and ZRANGE Commands

  • ZADD: Add one or more members to a sorted set.
  • ZRANGE: Return a range of members in a sorted set.
  127.0.0.1:6379> ZADD no 1 shubham
  (integer) 1
  127.0.0.1:6379> ZRANGE no 0 -1
  1) "shubham"
Enter fullscreen mode Exit fullscreen mode

HSET Command

  • HSET: Set fields in a hash stored at a specified key.
  127.0.0.1:6379> HSET bike:1 model Deimos brand Ergonom type 'Enduro bikes' price 4972
  (integer) 4
Enter fullscreen mode Exit fullscreen mode

PUBLISH Command

  • PUBLISH: Publish a message to channels.
  127.0.0.1:6379> PUBLISH notifications hey
  (integer) 1
Enter fullscreen mode Exit fullscreen mode

SUBSCRIBE Command

  • SUBSCRIBE: Subscribe to channels.
  127.0.0.1:6379> SUBSCRIBE notifications
  1) "subscribe"
  2) "notifications"
  3) (integer) 1
Enter fullscreen mode Exit fullscreen mode

Congratulations! You have successfully learned some basic Redis commands and functionalities. Redis offers a wide range of features for managing and manipulating data efficiently. Explore further to unlock the full potential of Redis in your applications.

๐Ÿš€ Happy coding with Redis! ๐ŸŽ‰

Top comments (0)