Class: TokyoTyrant::RDBTBL
- TokyoTyrant::RDB
- TokyoTyrant::RDBTBL
This class inherits the class "TokyoTyrant::RDB". All methods are specific to servers of the table database.%%
Constants
- ITDECIMAL
- 1
- ITKEEP
- 1 << 24
- ITLEXICAL
- 0
- ITOPT
- 9998
- ITQGRAM
- 3
- ITTOKEN
- 2
- ITVOID
- 9999
Constructor Summary
This class inherits a constructor from TokyoTyrant::RDB.
Public Visibility
Public Instance Method Summary
| #genuid |
Generate a unique ID number. |
|---|---|
| #get(pkey) |
Retrieve a record. |
| #mget(recs) |
Retrieve records. |
| #out(pkey) |
Remove a record. |
| #put(pkey, cols) |
Store a record. |
| #putcat(pkey, cols) |
Concatenate columns of the existing record. |
| #putkeep(pkey, cols) |
Store a new record. |
| #setindex(name, type) |
Set a column index. |
Public Instance Methods Inherited from TokyoTyrant::RDB
[], []=, adddouble, addint, clear, close, copy, delete, each, each_keys, each_values, ecode, empty?, errmsg, ext, fetch, fwmkeys, has_key?, has_value?, iterinit, iternext, keys, length, misc, open, optimize, putnr, putshl, rnum, size, stat, store, sync, values, vanish, vsiz
Public Instance Method Details
genuid
Generate a unique ID number.%% The return value is the new unique ID number or -1 on failure.%%
1243 1244 1245 1246 1247 |
# File 'lib/tokyotyrant.rb', line 1243 def genuid() rv = misc("genuid", Array::new, 0) return -1 if !rv return rv[0] end |
get
Retrieve a record.%% `pkey’ specifies the primary key.%% If successful, the return value is a hash of the columns of the corresponding record. `nil’ is returned if no record corresponds.%%
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 |
# File 'lib/tokyotyrant.rb', line 1189 def get(pkey) pkey = _argstr(pkey) args = Array::new args.push(pkey) rv = misc("get", args) if !rv @ecode = ENOREC if @ecode == EMISC return nil end cols = Hash::new() cnum = rv.length cnum -= 1 i = 0 while i < cnum cols[rv[i]] = rv[i+1] i += 2 end return cols end |
mget
Retrieve records.%% `recs’ specifies a hash containing the retrieval keys. As a result of this method, keys existing in the database have the corresponding columns and keys not existing in the database are removed.%% If successful, the return value is the number of retrieved records or -1 on failure.%% Due to the protocol restriction, this method can not handle records with binary columns including the "\0" chracter.%%
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 |
# File 'lib/tokyotyrant.rb', line 1212 def mget(recs) rv = super(recs) return -1 if rv < 0 recs.each do |pkey, value| cols = Hash::new cary = value.split("\0") cnum = cary.size - 1 i = 0 while i < cnum cols[cary[i]] = cary[i+1] i += 2 end recs[pkey] = cols end return rv end |
out
Remove a record.%% `pkey’ specifies the primary key.%% If successful, the return value is true, else, it is false.%%
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 |
# File 'lib/tokyotyrant.rb', line 1175 def out(pkey) pkey = _argstr(pkey) args = Array::new args.push(pkey) rv = misc("out", args, 0) if !rv @ecode = ENOREC if @ecode == EMISC return false end return true end |
put
Store a record.%% `pkey’ specifies the primary key.%% `cols’ specifies a hash containing columns.%% If successful, the return value is true, else, it is false.%% If a record with the same key exists in the database, it is overwritten.%%
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 |
# File 'lib/tokyotyrant.rb', line 1122 def put(pkey, cols) pkey = _argstr(pkey) raise ArgumentError if !cols.is_a?(Hash) args = Array::new args.push(pkey) cols.each do |ckey, cvalue| args.push(ckey) args.push(cvalue) end rv = misc("put", args, 0) return rv ? true : false end |
putcat
Concatenate columns of the existing record.%% `pkey’ specifies the primary key.%% `cols’ specifies a hash containing columns.%% If successful, the return value is true, else, it is false.%% If there is no corresponding record, a new record is created.%%
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 |
# File 'lib/tokyotyrant.rb', line 1160 def putcat(pkey, cols) pkey = _argstr(pkey) raise ArgumentError if !cols.is_a?(Hash) args = Array::new args.push(pkey) cols.each do |ckey, cvalue| args.push(ckey) args.push(cvalue) end rv = misc("putcat", args, 0) return rv ? true : false end |
putkeep
Store a new record.%% `pkey’ specifies the primary key.%% `cols’ specifies a hash containing columns.%% If successful, the return value is true, else, it is false.%% If a record with the same key exists in the database, this method has no effect.%%
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 |
# File 'lib/tokyotyrant.rb', line 1139 def putkeep(pkey, cols) pkey = _argstr(pkey) raise ArgumentError if !cols.is_a?(Hash) args = Array::new args.push(pkey) cols.each do |ckey, cvalue| args.push(ckey) args.push(cvalue) end rv = misc("putkeep", args, 0) if !rv @ecode = EKEEP if @ecode == EMISC return false end return true end |
setindex
Set a column index.%% `name’ specifies the name of a column. If the name of an existing index is specified, the index is rebuilt. An empty string means the primary key.%% `type’ specifies the index type: `TokyoTyrant::RDBTBL::ITLEXICAL’ for lexical string, `TokyoTyrant::RDBTBL::ITDECIMAL’ for decimal string, `TokyoTyrant::RDBTBL::ITTOKEN’ for token inverted index, `TokyoTyrant::RDBTBL::ITQGRAM’ for q-gram inverted index. If it is `TokyoTyrant::RDBTBL::ITOPT’, the index is optimized. If it is `TokyoTyrant::RDBTBL::ITVOID’, the index is removed. If `TokyoTyrant::RDBTBL::ITKEEP’ is added by bitwise-or and the index exists, this method merely returns failure.%% If successful, the return value is true, else, it is false.%%
1232 1233 1234 1235 1236 1237 1238 1239 1240 |
# File 'lib/tokyotyrant.rb', line 1232 def setindex(name, type) name = _argstr(name) type = _argnum(type) args = Array::new args.push(name) args.push(type) rv = misc("setindex", args, 0) return rv ? true : false end |