Giter VIP home page Giter VIP logo

redis_structures's Introduction

Logo

Data structures for Redis

Table of Contents

Versions:

  • v0.1 Build Status Requirements Status
  • master Build Status Requirements Status

Structures:

  • Queue
  • Priority queue
  • Stack
  • Circular buffer
  • Deque

Setup:

pip install -r requirements.txt
python setup.py install

Usage:

  • STACK: LIFO data structure
>>> from redis_structures import Stack
>>> stack = Stack(name='dummy_stack', host='127.0.0.1', port=6379)
>>> len(stack)
0
>>> stack.push('a_element')
>>> stack.push('another_element')
>>> stack.push('one_more_element') 
# same as doing stack.addAll(['a_element', 'another_element', 'one_more_element'])
>>> len(stack)
3
>>> stack.content()
['one_more_element', 'another_element', 'a_element']
>>> stack.pop()
'one_more_element'
>>> stack.content()
['another_element', 'a_element']
>>> stack.clear()
True
>>> stack.content()
[]
  • QUEUE: FIFO data structure
>>> from redis_structures import Queue
>>> queue = Queue(name='dummy_queue', host='127.0.0.1', port=6379)
>>> len(queue)
0
>>> queue.push('a_element')
>>> queue.push('another_element')
>>> queue.push('one_more_element')
# same as doing queue.addAll(['a_element', 'another_element', 'one_more_element'])
>>> len(queue)
3
>>> queue.content()
['one_more_element', 'another_element', 'a_element']
>>> queue.pop()
'a_element'
>>> queue.content()
['one_more_element', 'another_element']
>>> queue.clear()
True
>>> queue.content()
[]
  • PRIORITY QUEUE: Abstract data type where each element has a priority associated
>>> from redis_structures import PriorityQueue
>>> priority_queue = PriorityQueue(name='dummy_queue', host='127.0.0.1', port=6379)
>>> len(priority_queue)
0
>>> priority_queue.push('a_element', 20.0)
>>> priority_queue.push('another_element', 40.0)
>>> priority_queue.push('one_more_element', 10.0)
# same as doing priority_queue.addAll([('a_element', 20.0), ('another_element', 40.0), ('one_more_element', 10.0)])
>>> len(priority_queue)
3
>>> priority_queue.content()
[('one_more_element', 10.0), ('a_element', 20.0), ('another_element', 40.0)]
>>> priority_queue.pop()
('another_element', 40.0)
>>> priority_queue.content()
[('one_more_element', 10.0), ('a_element', 20.0)]
>>> priority_queue.clear()
True
>>> priority_queue.content()
[]
  • CIRCULAR BUFFER: Fixed-size buffer with connected end-to-end
>>> from redis_structures import CircularBuffer
>>> circular_buffer = CircularBuffer(name='dummy_cbuffer', size=3, host='127.0.0.1', port=6379)
>>> len(circular_buffer)
0
>>> circular_buffer.push('a_element')
>>> circular_buffer.push('another_element')
>>> circular_buffer.push('one_more_element')
# same as doing circular_buffer.addAll(['a_element', 'another_element', 'one_more_element'])
>>> len(circular_buffer)
3
>>> circular_buffer.content()
['one_more_element', 'another_element', 'a_element']
>>> circular_buffer.push('other_element!!') # overwriting old data because size=3
>>> len(circular_buffer)
3
>>> circular_buffer.content()
['other_element!!', 'one_more_element', 'another_element']
>>> circular_buffer.pop()
'another_element'
>>> circular_buffer.content()
['other_element!!', 'one_more_element',]
>>> circular_buffer.clear()
True
>>> circular_buffer.content()
[]
  • DEQUE: Double-ended queue also called head-tail linked list
>>> from redis_structures import Deque
>>> deque = Deque(name='dummy_cbuffer', host='127.0.0.1', port=6379)
>>> len(deque)
0
>>> deque.back_push('a_element')
>>> deque.back_push('another_element')
>>> deque.back_push('one_more_element')
# same as doing deque.addAll(['one_more_element', 'another_element', 'a_element'], back=True)
>>> len(deque)
3
>>> deque.content()
['one_more_element', 'another_element', 'a_element']
>>> deque.front_push('other_element!!')
>>> len(deque)
3
>>> deque.content()
['one_more_element', 'another_element', 'a_element', 'other_element!!']
>>> deque.back_pop()
'one_more_element'
>>> deque.content()
['another_element', 'a_element', 'other_element!!']
>>> deque.clear()
True
>>> deque.content()
[]

redis_structures's People

Contributors

msempere avatar

Stargazers

 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

Forkers

lordnynex

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.