Class: XBAD
- Inherits:
-
Object
- Object
- XBAD
- Defined in:
- ext/xbad/xbad.c
Instance Method Summary collapse
-
#find(key) ⇒ Object
rb_define_singleton_method(c, “initialize”, RUBY_METHOD_FUNC(XBAD_init), 3);.
- #initialize(_shmid, _hash_bits, _item_size) ⇒ Object constructor
- #store(key, value, _expire_after) ⇒ Object
- #store_and_broadcast(key, value, _expire_after, _port) ⇒ Object
Constructor Details
#initialize(_shmid, _hash_bits, _item_size) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'ext/xbad/xbad.c', line 18
static VALUE XBAD_init(VALUE self, VALUE _shmid, VALUE _hash_bits, VALUE _item_size ) {
int shmid = NUM2INT(_shmid);
int item_size = NUM2INT(_item_size);
int hash_bits = NUM2INT(_hash_bits);
struct shared_pool *sp = get_shared_pool(self);
shared_pool_init(sp,shmid,hash_bits,item_size);
return self;
}
|
Instance Method Details
#find(key) ⇒ Object
rb_define_singleton_method(c, “initialize”, RUBY_METHOD_FUNC(XBAD_init), 3);
55 56 57 58 59 60 61 62 63 64 |
# File 'ext/xbad/xbad.c', line 55
static VALUE XBAD_find(VALUE self, VALUE key) {
VALUE ret = Qnil;
struct shared_pool *sp = get_shared_pool(self);
struct item *item = t_find_and_lock(sp,RSTRING_PTR(key),RSTRING_LEN(key));
if (item) {
ret = rb_str_new(ITEM_BLOB(item),item->blob_len);
shared_pool_unlock_item(item);
}
return ret;
}
|
#store(key, value, _expire_after) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'ext/xbad/xbad.c', line 32
static VALUE XBAD_store(VALUE self, VALUE key, VALUE value, VALUE _expire_after) {
die_unless_string(key);
die_unless_string(value);
struct shared_pool *sp = get_shared_pool(self);
int expire_after = NUM2INT(_expire_after);
if (t_add(sp,RSTRING_PTR(key),RSTRING_LEN(key),RSTRING_PTR(value),RSTRING_LEN(value),expire_after) != 0)
rb_raise(rb_eArgError,"failed to store");
return value;
}
|
#store_and_broadcast(key, value, _expire_after, _port) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'ext/xbad/xbad.c', line 42
static VALUE XBAD_store_and_broadcast(VALUE self, VALUE key, VALUE value, VALUE _expire_after,VALUE _port) {
die_unless_string(key);
die_unless_string(value);
struct shared_pool *sp = get_shared_pool(self);
int expire_after = NUM2INT(_expire_after);
unsigned short port = NUM2INT(_port);
struct in_addr ip = { .s_addr = htonl(0xffffffff) };
if (t_add_and_sent_to(sp,RSTRING_PTR(key),RSTRING_LEN(key),RSTRING_PTR(value),RSTRING_LEN(value),expire_after,ip,port) != 0)
rb_raise(rb_eArgError,"failed to store and broadcast");
return value;
}
|