Class: TokyoTyrant::BDB

Inherits:
DB
  • Object
show all
Defined in:
ext/tokyo_tyrant.c

Constant Summary

Constants included from TokyoTyrant

EINVALID, EKEEP, EMISC, ENOHOST, ENOREC, ERECV, EREFUSED, ESEND, ESUCCESS, ITDECIMAL, ITKEEP, ITLEXICAL, ITVOID

Instance Method Summary collapse

Methods inherited from DB

#each_value, #fetch, #get, #put, #putcat, #putkeep, #putnr, #putshl, #vsiz

Methods included from TokyoTyrant

#add_double, #add_int, #check, #close, #copy, #db_size, #delete_keys_with_prefix, #each_key, #ecode, #empty?, #errmsg, #ext, #fwmkeys, #get_double, #get_int, #iterinit, #iternext, #keys, #misc, #optimize, #out, #outlist, #reconnect, #restore, #rnum, #server, #setmst, #stat, #sync, #vanish

Instance Method Details

#eachObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'ext/tokyo_tyrant_bdb.c', line 77

static VALUE cBDB_each(VALUE vself){
  VALUE vrv = Qnil;
  const char *kbuf, *vbuf;
  int ksiz, vsiz;
  TCLIST *result;
  TCRDB *db = mTokyoTyrant_getdb(vself);

  if(!rb_block_given_p()) rb_raise(rb_eArgError, "no block given");

  tcrdbiterinit(db);
  tcrdbmisc(db, "iterinit", RDBMONOULOG, tclistnew());
  while((result = tcrdbmisc(db, "iternext", RDBMONOULOG, tclistnew())) != NULL){
    if (tclistnum(result) == 2) {
      kbuf = tclistval(result, 0, &ksiz);
      vbuf = tclistval(result, 1, &vsiz);
      vrv = rb_yield_values(2, rb_str_new(kbuf, ksiz), rb_str_new(vbuf, vsiz));
    }
    tclistdel(result);
  }
  return vrv;
}

#getlist(*args) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'ext/tokyo_tyrant_bdb.c', line 44

static VALUE cBDB_getlist(int argc, VALUE *argv, VALUE vself){
  VALUE vkeys, vval;
  VALUE vhash = rb_hash_new();
  TCLIST *list, *result;
  TCRDB *db = mTokyoTyrant_getdb(vself);
  rb_scan_args(argc, argv, "*", &vkeys);

  // I really hope there is a better way to do this
  if (RARRAY_LEN(vkeys) == 1) {
    vval = rb_ary_entry(vkeys, 0);
    switch (TYPE(vval)){
      case T_STRING:
      case T_FIXNUM:
        break;
      case T_ARRAY:
        vkeys = vval;
        break;
      case T_OBJECT:
        vkeys = rb_convert_type(vval, T_ARRAY, "Array", "to_a");
        break;
    }
  }
  Check_Type(vkeys, T_ARRAY);

  list = varytolist(vkeys);
  if ((result = tcrdbmisc(db, "getlist", RDBMONOULOG, list)) != NULL){
    vhash = listtovhash(result);
    tclistdel(result);
  }
  tclistdel(list);
  return vhash;
}

#putdup(vkey, vval) ⇒ Object



119
120
121
# File 'ext/tokyo_tyrant_bdb.c', line 119

static VALUE cBDB_putdup(VALUE vself, VALUE vkey, VALUE vval){
  return cBDB_put_method(vself, vkey, vval, "putdup", false);
}

#putdup!(vkey, vval) ⇒ Object



123
124
125
# File 'ext/tokyo_tyrant_bdb.c', line 123

static VALUE cBDB_putdup_bang(VALUE vself, VALUE vkey, VALUE vval){
  return cBDB_put_method(vself, vkey, vval, "putdup", true);
}

#putlist(vhash) ⇒ Object Also known as: mput, mget



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'ext/tokyo_tyrant_bdb.c', line 28

static VALUE cBDB_putlist(VALUE vself, VALUE vhash){
  VALUE vary = rb_ary_new();
  TCLIST *list, *result;
  TCRDB *db = mTokyoTyrant_getdb(vself);
  Check_Type(vhash, T_HASH);

  list = vhashtoputlist(vhash);
  if ((result = tcrdbmisc(db, "putlist", 0, list)) != NULL){
    vary = listtovary(result);
    tclistdel(result);
  }
  tclistdel(list);

  return vary;
}

#valuesObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'ext/tokyo_tyrant_bdb.c', line 99

static VALUE cBDB_values(VALUE vself){
  VALUE vary = rb_ary_new();
  const char *vbuf;
  int vsiz;
  TCLIST *result;
  TCRDB *db = mTokyoTyrant_getdb(vself);

  tcrdbiterinit(db);
  tcrdbmisc(db, "iterinit", RDBMONOULOG, tclistnew());
  while((result = tcrdbmisc(db, "iternext", RDBMONOULOG, tclistnew())) != NULL){
    if (tclistnum(result) == 2){
      vbuf = tclistval(result, 1, &vsiz);
      vary = rb_ary_push(vary, rb_str_new(vbuf, vsiz));
    }
    tclistdel(result);
  }

  return vary;
}