Giter VIP home page Giter VIP logo

ru101's Introduction

Redis University RU101: Introduction to Redis Data Structures

Introduction

This repo contains the sample data and Python code for RU101, Introduction to Redis Data Structures at Redis University.

Setup

Redis Stack is an easy to install bundle of Redis plus additional capabilities. You'll need to clone this repository to your machine, and setup Redis Stack and Python as described below. Read more about Redis Stack here.

Redis Stack

There are multiple ways that you can install Redis Stack, options include:

Python

This course requires Python 3. You should create and use a virtual environment when running the code and loading the sample data into Redis. You'll also need to set your PYTHONPATH environment variable:

$ git clone https://github.com/redislabs-training/ru101.git
$ cd ru101
$ export PYTHONPATH=`pwd`
$ python3 -m venv venv
$ . venv/bin/activate
$ pip install -r requirements.txt

Configuration

The data loader and sample code expect Redis to be running at localhost:6379 with no password set. This is the default, but if your Redis instance uses a different hostname, port, or has a password, you should set the appropriate environment variables:

$ export REDIS_HOST=myredishost
$ export REDIS_PORT=9999
$ export REDIS_PASSWORD=ssssh

Network Latency

Running the Redis server and the Python code on different machines introduces round trip network latency for each Redis command sent from Python to Redis. To keep the example code simple, some of the Python scripts for this course send each command to Redis separately.

To get the most performance from applications using Redis, we recommend the use of pipelining to send multiple commands to the server in a single round trip where possible. You should also ensure that the application code and Redis server are on hosts with minimal latency between them. These concepts are covered in more detail in the following programming language specific Redis University courses:

To get the best performance from the simple demo scripts for this course, you should run the code and the Redis server on the same local network or the same machine if possible.

Loading the Sample Data

To answer some of the homework and exam questions, and to run the sample code, you'll need to load the sample data into Redis. Skip this step if you chose to use a Cloud Redis Stack instance as you will have loaded the data as part of the database setup.

If you're running Redis Stack locally or via Docker, go ahead and load the data as follows:

$ cd redisu
$ python utils/dumpload.py load ru101/data/ru101.json

If the sample data was loaded correctly, you should see the following message:

total keys loaded: 14328

Using redis-cli

Some of the quiz, homework and exam questions for this course may require you to use the Redis command line interface to execute commands. Start redis-cli from the command line as follows:

$ redis-cli
127.0.0.1:6379>

You can then enter Redis commands, for example to see how many keys are in the database use dbsize:

127.0.0.1:6379> dbsize
(integer) 14328
127.0.0.1:6379>

If you prefer a more graphical user interface, try RedisInsight, a free tool for exploring and interacting with Redis that includes an embedded redis-cli.

Running the Code

To run the example code, cd to the directory containing the script you wish to run, and pass the script name to the python command.

Example:

$ cd redisu/ru101/uc01-faceted-search
$ python search.py

Need Help or Have Questions?

If you need help, have questions, or want to chat about all things Redis, please join us on the Redis University Discord Server.

Subscribe to our YouTube Channel / Follow us on Twitch

We'd love for you to check out our YouTube channel, and subscribe if you want to see more Redis videos! We also stream regularly on our Twitch.tv channel - follow us to be notified when we're live.

ru101's People

Contributors

andrewvasilchuk avatar imrankhanatsuncity avatar simonprickett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ru101's Issues

TypeError in seat_reservation.py

Error reported on Discord with https://github.com/redislabs-training/ru101/blob/main/redisu/ru101/uc03-seat-reservation/seat_reservation.py

Received error when running seat reservation python.

        (_, tier_name, blockname) = block.rsplit(":", 2)
                                       ^^^^^^^^^^^^^^^^^^^^
         TypeError: a bytes-like object is required, not 'str'

Resolved by adding extra line to do the conversion. Tried using Python 3.11 and 3.8. It maybe a python 2 versus 3 difference....

Added a line to do conversion and it works fine.

    block = block.decode("utf-8") 
    (, tier_name, block_name) = block.rsplit(":", 2)

Look into this and adjust as needed.

Speed up Python scan code

Note from a student via Discord:

scan_iter in the code samples run painfully slowly. Running the faceted search code can take 5 minutes +. is that normal for such a small sample (referencing cloud redis). it looks looked like it was doing 1 record at a time so i changed to scan_iter( pattern, count=1000) - now it runs in a few seconds

Problems running python code

Hi,
I've tried to run the code using the README and ran into a problem when I tried executing uc01-faceted-search/search.py.

Traceback (most recent call last):
  File "/home/stonecharioteer/code/learning/redis-labs-datastructures/redisu/ru101/uc01-faceted-search/search.py", line 8, in <module>
    import redisu.utils.keynamehelper as keynamehelper
ModuleNotFoundError: No module named 'redisu'

The folder exists, but it seems unable to identify it. This is possibly because there are no __init__.py files. I'm using Python 3.9.2.

Example code doesn't run with Python 3.12

It looks like with Python 3.12 that the distutils package that redis-py uses isn't present. This was raised by a student on Discord:

โžœ python redisu/ru101/uc01-faceted-search/search.py
Traceback (most recent call last):
  File "/home/nbarreiro/Repos/redis-university/ru101/redisu/ru101/uc01-faceted-search/search.py", line 4, in <module>
    from redis import Redis
  File "/home/nbarreiro/Repos/redis-university/ru101/venv/lib/python3.12/site-packages/redis/__init__.py", line 1, in <module>
    from redis.client import Redis, StrictRedis
  File "/home/nbarreiro/Repos/redis-university/ru101/venv/lib/python3.12/site-packages/redis/client.py", line 12, in <module>
    from redis.connection import (ConnectionPool, UnixDomainSocketConnection,
  File "/home/nbarreiro/Repos/redis-university/ru101/venv/lib/python3.12/site-packages/redis/connection.py", line 2, in <module>
    from distutils.version import StrictVersion
ModuleNotFoundError: No module named 'distutils'

Try upgrading the version of redis-py used in this course: https://github.com/redislabs-training/ru101/blob/main/requirements.txt - currently quite old (3.0.1).

RU101 - Week2 - Error in First Video of "Capped Collections & Set Operations" Section

Dear Redis Team,

I would like to report an error identified in the first video of the "Capped Collections & Set Operations" section of week2 in the RU101 course. The error pertains to the explanation provided regarding the usage of the "ZREMRANGEBYRANK" command.

The video incorrectly states that "ZREMRANGEBYRANK" is used to trim the lowest-scoring element. However, based on my understanding and Redis documentation, "ZREMRANGEBYRANK" is actually used to remove elements from a sorted set by their rank/index range, rather than by their scores.

Could you please review and correct this information in the video, or add errata to ensure accuracy for learners?

Thank you for your attention to this matter.

Sincerely,
Mubasher Naeem

Screenshot 2024-02-28 165405

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.