Giter VIP home page Giter VIP logo

redissnowflake's Introduction

Redis Snowflake

Written by Eran Sandler (@erans)

This is a simple Redis module which generates unique IDs based on Twitter's Snowflake at high scale with some simple guarantees.

This Redis module wraps code from snowflaked made by Dwayn Matthies (dwayn). Thanks for the code Dwayn!

Some of Snowflake's benefits include:

  • Uncoordinated - For high availability within and across data centers, machines generating IDs should not have to coordinate with each other.

  • (Roughly) Time Ordered - it can guarantee that the ID numbers will be k-sorted (references: http://portal.acm.org/citation.cfm?id=70413.70419 and http://portal.acm.org/citation.cfm?id=110778.110783) within a reasonable bound (1 second is currently promised).

  • Directly Sortable - The IDs are sortable without loading the full objects that they represent, using the above order.

  • Compact - There are many otherwise reasonable solutions to this problem that require 128 bit numbers. For various reasons, we need to keep our IDs under 64 bits.

ID Composition

  • time - 41 bits (millisecond precision w/ a custom epoch gives us 69 years)
  • region_id - 4 bits - gives us 16 different region or data centers to work with
  • worker_id - 10 bits - gives us up to 1024 workers per region_id
  • sequence_id - 8 bits - gives us up to 256 IDs per worker in the same millisecond

Compilation

Just make it.

Usage

redis-server --loadmodule redissnowflake.so [region_id] [worker_id]

Example:

redis-server --loadmodule redissnowflake.so 1 1

If you require multiple such server/services in the same region, change the worker_id value.

If you require multiple such server/services in different regions, change the region_id value.

redissnowflake's People

Contributors

erans avatar waltertross 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

Watchers

 avatar  avatar  avatar  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.