Custom structures

24 views
Skip to first unread message

Alvaro

unread,
May 7, 2012, 6:48:43 AM5/7/12
to python...@googlegroups.com


Hi there,

I'm trying to create a custom data structure for storing bit sets, so I want to create my own class that inherits from Zset but with some convenience methods. These bitsets will not grow too much in size, so a Zset would be a good fit: I could get good enough performance while having convenient features.

This is an example of what I'm trying to achieve:

class BitsSet(Zset):
    def __index__(self, idx, val):
        ...
    
    def from_string(self, s):
        ...

class BitsSetField(orm.SetField):

    def structure_class(self):
        return BitsSet


However, it seems that stdnet does not like the idea of having this kind of custom structures because it doesn't know how to store it in the Redis backend. Is there any way I could specify this is just a Zset so that stdnet could use it?


Thanks in advance!


Alvaro






lsbardel

unread,
May 8, 2012, 5:33:26 AM5/8/12
to python...@googlegroups.com
If you define a new structure class you need to make sure the backend (in your case redis) knows how to handle it.
If your new structure doesn't do anything fundamentally different from its parent class, and simply adds convenience methods, you could use the following trick

from stdnet.backends import redisb
redisb.BackendDataServer.struct_map['bitset'] = redisb.BackendDataServer.struct_map['zset']

in other words you use the same backend structure implementation as zset.
Alternatively you could write a specialised backlend structure for redis in this way

class RedisBitSet(redisb.Zset):
    ...

redisb.BackendDataServer.struct_map['bitset'] = RedisBitSet

Luca
Reply all
Reply to author
Forward
0 new messages