Skip to content

ranedk/kvds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#### This is the development branch, stable versions will be pushed to git://github.com/amitu/dutils.git ####

Setting up Tokyo Cabinet, Tokyo Tyrant

    - Tokyo Cabinet is a high performance key/value data store. Without the overheads of mysql the performance beats relational databases hands down. Since it is not able to handle relational designs very effectively, it ends up restricting itself to database architectures which do not need normalization. Tokyo Tyrant is a wrapper over tokyo cabinet and provides network interface. To install 
    - get the latest version of tokyo cabinet and tokyo tyrant from http://1978th.net
    - compile and install cabinet, followed by tyrant. Remember to compile tyrant with lua extensions using `./configure --enable-lua`
    - Start the server with the command "ttserver -ulog tyrant.log -sid 1 t.tch"
  
    By default the server runs on port 1978 

Setting up django-kvds server
    - django-kvds server is a http wrapper over tyrant using python-django framework
    - get the latest version from https://github.com/amitu/dutils/blob/master/kvds_server.py 
         $> git clone git://github.com/amitu/dutils.git
    - inside dutils the file kvds_server.py contains the required views to manage tyrant through http
    - put dutils in your python path
    - to use this, add the following: (r'', include('dutils.kvds_server')), to your urls.py to activate and use this server.
    - Start the server (either the debug server using "python manage.py runserver" or load in apache server)
    - visit the base url to see if you can save a key->value pair and retrieve it using the same key.
    
Making Models, initializing, saving and retrieving
    - kvds is a "object key-value mapper" which has a django like structure to manage models with the django-kvds data store(above)
    - $> git clone git://github.com/ranedk/kvds.git 
    - put kvds in your python path
    - sample run

from kvds.models import *
from kvds.fields import *

#Create a model inherited from Model
class Amodel(Model):
    key_prefix = 'kvds__a__comment'
    a1 = Field()
    a2 = Field()
    a3 = Field()

class Bmodel(Model):
    key_prefix = 'kvds__b__comment'
    b1 = Field()
    b2 = Field()
    ba = ForeignKey(Amodel)

class Cmodel(Model):
    key_prefix = 'kvds__c__comment'
    c1 = Field()
    c2 = Field()
    c3 = Field()

class Composite(Model):
    key_prefix = 'kvds__composite'
    compa = Field()
    compb = ManyToManyField(Cmodel)
    compc = ForeignKey(Bmodel)
    pid = Field(index=True)

a1item = Amodel(
            a1='itema1a1', 
            a2='itema1a2', 
            a3='itema1a3'
        )
b1item = Bmodel(
            b1='itema2a1', 
            b2='itema2a2', 
            ba=a1item
        )
c1item = Cmodel(
            c1='itemc1c1', 
            c2='itemc1c2', 
            c3='itemc1c3'
        )
c2item = Cmodel(
            c1='itemc2c1', 
            c2='itemc2c2', 
            c3='itemc2c3'
        )

comp_obj = Composite(
            compa='Random values here', 
            compb=[c1item,c2item], 
            compc=b1item, 
            pid="23413423"
        )
comp_obj.save()

comp_new = Composite.get(id=comp_obj.id)


Advanced: Extending Fields

    - To add a new field type (check fields.py), inherit from Field
    - TODO: Complete documentation for extending fields and add DateTimeField as example

About

Django Model Layer for Tokyo Tyrant

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages