GithubHelp home page GithubHelp logo

miniredis's Introduction

miniredis

A minimal implementation of an in memory key value store. This is a toy project to learn more about redis and C++. It is not intended to be used in production.

Build

Or use some other build system of your choice.

mkdir build
cd build
cmake ..
make

Run

./miniredis

Folder structure

The main entry point is server.cpp This contains the main level abstraction and implementation of the server. The other files in the folder are generic implementations of different data structures in use in the server.

Server

  • main() gets back a file descriptor from the kernel and sets up a listening socket connection with an addr.
  • main then handles incoming connections. When a connection is accepted, a new thread is spawned to handle the connection.
  • When a connection is made, it will contain a header and some data. The header contains the length of the data.
  • The data will have some type of request. The server will parse the request and send back a response.

Commands

The server implements the following commands. The commands are case sensitive.

  • keys - returns all keys in the store
  • get <key> - returns the value of the key
  • set <key> <value> - sets the value of the key
  • del <key> - deletes the key
  • pexpire <key> <time> - sets the expiration time of the key in milliseconds
  • pttl <key> - returns the time to live of the key in milliseconds
  • zadd <key> <score> <value> - adds a value to a sorted set with a score
  • zrem <key> <value> - removes a value from a sorted set
  • zscore <key> <value> - returns the score of a value in a sorted set
  • zquery <key> <min> <max> <offset> <count> - returns a range of values in a sorted set

These are only a few commands, but implements the basic functionality you would expect in redis.

miniredis's People

Contributors

neilshevlin avatar

Watchers

 avatar  avatar

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.