Class: TokyoTyrant::RDB

Remote database is a set of interfaces to use an abstract database of Tokyo Cabinet, mediated by a server of Tokyo Tyrant. Before operations to store or retrieve records, it is necessary to connect the remote database object to the server. The method `open’ is used to open a database connection and the method `close’ is used to close the connection.%%

Constants

EINVALID
1
EKEEP
6
EMISC
9999
ENOHOST
2
ENOREC
7
ERECV
5
EREFUSED
3
ESEND
4
ESUCCESS
0
MONOULOG
1 << 0
XOLCKGLB
1 << 1
XOLCKREC
1 << 0

Constructor Summary

public initialize

Create a remote database object.%% The return value is the new remote database object.%%

[View source]


58
59
60
61
62
# File 'lib/tokyotyrant.rb', line 58

def initialize()
  @ecode = ESUCCESS
  @enc = nil
  @sock = nil
end

Public Visibility

Public Instance Method Summary

#[](key)

Hash-compatible method.

#[]=(key, value)

Hash-compatible method.

#adddouble(key, num)

Add a real number to a record.

#addint(key, num = 0)

Add an integer to a record.

#clear

Hash-compatible method.

#close

Close the database connection.

#copy(path)

Copy the database file.

#delete(key)

Hash-compatible method.

#each #each_pair

Hash-compatible method.

#each_keys

Hash-compatible method.

#each_values

Hash-compatible method.

#ecode

Get the last happened error code.

#empty?

Hash-compatible method.

#errmsg(ecode = nil)

Get the message string corresponding to an error code.

#ext(name, key = "", value = "", opts = 0)

Call a function of the script language extension.

#fetch(key)

Hash-compatible method.

#fwmkeys(prefix, max = -1)

Get forward matching keys.

#get(key)

Retrieve a record.

#has_key?(key)

Hash-compatible method.

#has_value?(value)

Hash-compatible method.

#iterinit

Initialize the iterator.

#iternext

Get the next key of the iterator.

#keys

Hash-compatible method.

#length

Hash-compatible method.

#mget(recs)

Retrieve records.

#misc(name, args = [], opts = 0)

Call a versatile function for miscellaneous operations.

#open(host, port = 0)

Open a remote database connection.

#optimize(params = nil)

Optimize the storage.

#out(key)

Remove a record.

#put(key, value)

Store a record.

#putcat(key, value)

Concatenate a value at the end of the existing record.

#putkeep(key, value)

Store a new record.

#putnr(key, value)

Store a record without response from the server.

#putshl(key, value, width = 0)

Concatenate a value at the end of the existing record and shift it to the left.

#rnum

Get the number of records.

#size

Get the size of the database.

#stat

Get the status string of the database server.

#store(key, value)

Hash-compatible method.

#sync

Synchronize updated contents with the file and the device.

#values

Hash-compatible method.

#vanish

Remove all records.

#vsiz(key)

Get the size of the value of a record.

Public Instance Method Details

[]

public [](key)

Hash-compatible method.%% Alias of `get’.%%

[View source]


933
934
935
# File 'lib/tokyotyrant.rb', line 933

def [](key)
  return get(key)
end

[]=

public []=(key, value)

Hash-compatible method.%% Alias of `put’.%%

[View source]


928
929
930
# File 'lib/tokyotyrant.rb', line 928

def []=(key, value)
  return put(key, value)
end

adddouble

public adddouble(key, num)

Add a real number to a record.%% `key’ specifies the key.%% `num’ specifies the additional value. If it is not defined, 0 is specified.%% If successful, the return value is the summation value, else, it is `nil’.%% If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack’ function with the `d’ operator after retrieval.%%

[View source]


569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
# File 'lib/tokyotyrant.rb', line 569

def adddouble(key, num)
  key = _argstr(key)
  num = _argnum(num)
  if !@sock
    @ecode = EINVALID
    return nil
  end
  integ = num.truncate
  fract = ((num - integ) * 1000000000000).truncate
  sbuf = [0xC8, 0x61, key.length].pack("CCN")
  sbuf += _packquad(integ) + _packquad(fract) + key
  if !_send(sbuf)
    @ecode = ESEND
    return nil
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return nil
  end
  if code != 0
    @ecode = EKEEP
    return nil
  end
  integ = _recvint64()
  fract = _recvint64()
  return integ + fract / 1000000000000.0
end

addint

public addint(key, num = 0)

Add an integer to a record.%% `key’ specifies the key.%% `num’ specifies the additional value. If it is not defined, 0 is specified.%% If successful, the return value is the summation value, else, it is `nil’.%% If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the `unpack’ function with the `i’ operator after retrieval.%%

[View source]


540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/tokyotyrant.rb', line 540

def addint(key, num = 0)
  key = _argstr(key)
  num = _argnum(num)
  if !@sock
    @ecode = EINVALID
    return nil
  end
  sbuf = [0xC8, 0x60, key.length, num].pack("CCNN")
  sbuf += key
  if !_send(sbuf)
    @ecode = ESEND
    return nil
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return nil
  end
  if code != 0
    @ecode = EKEEP
    return nil
  end
  return _recvint32
end

clear

public clear

Hash-compatible method.%% Alias of `vanish’.%%

[View source]


913
914
915
# File 'lib/tokyotyrant.rb', line 913

def clear
  return vanish
end

close

public close

Close the database connection.%% If successful, the return value is true, else, it is false.%%

[View source]


139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/tokyotyrant.rb', line 139

def close()
  if !@sock
    @ecode = EINVALID
    return false
  end
  begin
    @sock.close
  rescue Exception
    @ecode = EMISC
    @sock = nil
    return false
  end
  @sock = nil
  return true
end

copy

public copy(path)

Copy the database file.%% `path’ specifies the path of the destination file. If it begins with `@’, the trailing substring is executed as a command line.%% If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.%% The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.%%

[View source]


715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
# File 'lib/tokyotyrant.rb', line 715

def copy(path)
  path = _argstr(path)
  if !@sock
    @ecode = EINVALID
    return false
  end
  sbuf = [0xC8, 0x73, path.length].pack("CCN")
  sbuf += path
  if !_send(sbuf)
    @ecode = ESEND
    return false
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return false
  end
  if code != 0
    @ecode = EMISC
    return false
  end
  return true
end

delete

public delete(key)

Hash-compatible method.%% Alias of `out’.%%

[View source]


887
888
889
# File 'lib/tokyotyrant.rb', line 887

def delete(key)
  return out(key)
end

each

public each

Also known as: each_pair

Hash-compatible method.%% Iterator of pairs of the key and the value.%%

[View source]


938
939
940
941
942
943
944
945
946
# File 'lib/tokyotyrant.rb', line 938

def each
  return nil if !iterinit
  while key = iternext
    value = get(key)
    break if !value
    yield(key, value)
  end
  return nil
end

each_keys

public each_keys

Hash-compatible method.%% Iterator of the keys.%%

[View source]


950
951
952
953
954
955
956
# File 'lib/tokyotyrant.rb', line 950

def each_keys
  return nil if !iterinit
  while key = iternext
    yield(key)
  end
  return nil
end

each_values

public each_values

Hash-compatible method.%% Iterator of the values.%%

[View source]


959
960
961
962
963
964
965
966
967
# File 'lib/tokyotyrant.rb', line 959

def each_values
  return nil if !iterinit
  while key = iternext
    value = get(key)
    break if !value
    yield(value)
  end
  return nil
end

ecode

public ecode

Get the last happened error code.%% The return value is the last happened error code.%% The following error code is defined: `TokyoTyrant::RDB::ESUCCESS’ for success, `TokyoTyrant::RDB::EINVALID’ for invalid operation, `TokyoTyrant::RDB::ENOHOST’ for host not found, `TokyoTyrant::RDB::EREFUSED’ for connection refused, `TokyoTyrant::RDB::ESEND’ for send error, `TokyoTyrant::RDB::ERECV’ for recv error, `TokyoTyrant::RDB::EKEEP’ for existing record, `TokyoTyrant::RDB::ENOREC’ for no record found, `TokyoTyrant::RDB::EMISC’ for miscellaneous error.%%

[View source]


92
93
94
# File 'lib/tokyotyrant.rb', line 92

def ecode()
  return @ecode
end

empty?

public empty?

Hash-compatible method.%% Alias of `rnum < 1’.%%

[View source]


923
924
925
# File 'lib/tokyotyrant.rb', line 923

def empty?
  return rnum < 1
end

errmsg

public errmsg(ecode = nil)

Get the message string corresponding to an error code.%% `ecode’ specifies the error code. If it is not defined or negative, the last happened error code is specified.%% The return value is the message string of the error code.%%

[View source]


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/tokyotyrant.rb', line 66

def errmsg(ecode = nil)
  ecode = @ecode if !ecode
  if ecode == ESUCCESS
    return "success"
  elsif ecode == EINVALID
    return "invalid operation"
  elsif ecode == ENOHOST
    return "host not found"
  elsif ecode == EREFUSED
    return "connection refused"
  elsif ecode == ESEND
    return "send error"
  elsif ecode == ERECV
    return "recv error"
  elsif ecode == EKEEP
    return "existing record"
  elsif ecode == ENOREC
    return "no record found"
  elsif ecode == EMISC
    return "miscellaneous error"
  end
  return "unknown"
end

ext

public ext(name, key = "", value = "", opts = 0)

Call a function of the script language extension.%% `name’ specifies the function name.%% `key’ specifies the key. If it is not defined, an empty string is specified.%% `value’ specifies the value. If it is not defined, an empty string is specified.%% `opts’ specifies options by bitwise-or: `TokyoTyrant::RDB::XOLCKREC’ for record locking, `TokyoTyrant::RDB::XOLCKGLB’ for global locking. If it is not defined, no option is specified.%% If successful, the return value is the value of the response or `nil’ on failure.%%

[View source]


603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'lib/tokyotyrant.rb', line 603

def ext(name, key = "", value = "", opts = 0)
  name = _argstr(name)
  key = _argstr(key)
  value = _argstr(value)
  opts = _argnum(opts)
  if !@sock
    @ecode = EINVALID
    return nil
  end
  sbuf = [0xC8, 0x68, name.length, opts, key.length, value.length].pack("CCNNNN")
  sbuf += name + key + value
  if !_send(sbuf)
    @ecode = ESEND
    return nil
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return nil
  end
  if code != 0
    @ecode = EMISC
    return nil
  end
  vsiz = _recvint32
  if vsiz < 0
    @ecode = ERECV
    return nil
  end
  vbuf = _recv(vsiz)
  if !vbuf
    @ecode = ERECV
    return nil
  end
  return _retstr(vbuf)
end

fetch

public fetch(key)

Hash-compatible method.%% Alias of `get’.%%

[View source]


892
893
894
# File 'lib/tokyotyrant.rb', line 892

def fetch(key)
  return get(key)
end

fwmkeys

public fwmkeys(prefix, max = -1)

Get forward matching keys.%% `prefix’ specifies the prefix of the corresponding keys.%% `max’ specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.%% The return value is an array of the keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.%% Note that this method may be very slow because every key in the database is scanned.%%

[View source]


492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/tokyotyrant.rb', line 492

def fwmkeys(prefix, max = -1)
  prefix = _argstr(prefix)
  max = _argnum(max)
  if !@sock
    @ecode = EINVALID
    return Array::new
  end
  sbuf = [0xC8, 0x58, prefix.length, max].pack("CCNN")
  sbuf += prefix
  if !_send(sbuf)
    @ecode = ESEND
    return Array::new
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return Array::new
  end
  if code != 0
    @ecode = ENOREC
    return Array::new
  end
  knum = _recvint32
  if knum < 0
    @ecode = ERECV
    return Array::new
  end
  keys = Array::new
  for i in 1..knum
    ksiz = _recvint32()
    if ksiz < 0
      @ecode = ERECV
      return Array::new
    end
    kbuf = _recv(ksiz)
    if !kbuf
      @ecode = ERECV
      return Array::new
    end
    keys.push(_retstr(kbuf))
  end
  return keys
end

get

public get(key)

Retrieve a record.%% `key’ specifies the key.%% If successful, the return value is the value of the corresponding record. `nil’ is returned if no record corresponds.%%

[View source]


321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/tokyotyrant.rb', line 321

def get(key)
  key = _argstr(key)
  sbuf = [0xC8, 0x30, key.length].pack("CCN")
  sbuf += key
  if !_send(sbuf)
    @ecode = ESEND
    return nil
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return nil
  end
  if code != 0
    @ecode = ENOREC
    return nil
  end
  vsiz = _recvint32
  if vsiz < 0
    @ecode = ERECV
    return nil
  end
  vbuf = _recv(vsiz)
  if !vbuf
    @ecode = ERECV
    return nil
  end
  return _retstr(vbuf)
end

has_key?

public has_key?(key)

Hash-compatible method.%% Check existence of a key.%%

[View source]


897
898
899
# File 'lib/tokyotyrant.rb', line 897

def has_key?(key)
  return vsiz(key) >= 0
end

has_value?

public has_value?(value)

Hash-compatible method.%% Check existence of a value.%%

[View source]


902
903
904
905
906
907
908
909
910
# File 'lib/tokyotyrant.rb', line 902

def has_value?(value)
  return nil if !iterinit
  while tkey = iternext
    tvalue = get(tkey)
    break if !tvalue
    return true if value == tvalue
  end
  return false
end

iterinit

public iterinit

Initialize the iterator.%% If successful, the return value is true, else, it is false.%% The iterator is used in order to access the key of every record stored in a database.%%

[View source]


432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/tokyotyrant.rb', line 432

def iterinit()
  if !@sock
    @ecode = EINVALID
    return false
  end
  sbuf = [0xC8, 0x50].pack("CC")
  if !_send(sbuf)
    @ecode = ESEND
    return false
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return false
  end
  if code != 0
    @ecode = EMISC
    return false
  end
  return true
end

iternext

public iternext

Get the next key of the iterator.%% If successful, the return value is the next key, else, it is `nil’. `nil’ is returned when no record is to be get out of the iterator.%% It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.%%

[View source]


456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'lib/tokyotyrant.rb', line 456

def iternext()
  if !@sock
    @ecode = EINVALID
    return nil
  end
  sbuf = [0xC8, 0x51].pack("CC")
  if !_send(sbuf)
    @ecode = ESEND
    return nil
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return nil
  end
  if code != 0
    @ecode = ENOREC
    return nil
  end
  vsiz = _recvint32
  if vsiz < 0
    @ecode = ERECV
    return nil
  end
  vbuf = _recv(vsiz)
  if !vbuf
    @ecode = ERECV
    return nil
  end
  return _retstr(vbuf)
end

keys

public keys

Hash-compatible method.%% Get an array of all keys.%%

[View source]


970
971
972
973
974
975
976
977
# File 'lib/tokyotyrant.rb', line 970

def keys
  tkeys = Array::new
  return tkeys if !iterinit
  while key = iternext
    tkeys.push(key)
  end
  return tkeys
end

length

public length

Hash-compatible method.%% Alias of `rnum’.%%

[View source]


918
919
920
# File 'lib/tokyotyrant.rb', line 918

def length
  return rnum
end

mget

public mget(recs)

Retrieve records.%% `recs’ specifies a hash containing the retrieval keys. As a result of this method, keys existing in the database have the corresponding values and keys not existing in the database are removed.%% If successful, the return value is the number of retrieved records or -1 on failure.%%

Meta Tags

Raises:

[ArgumentError]
[View source]


353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/tokyotyrant.rb', line 353

def mget(recs)
  raise ArgumentError if !recs.is_a?(Hash)
  if !@sock
    @ecode = EINVALID
    return -1
  end
  rnum = 0
  sbuf = ""
  recs.each_pair do |key, value|
    key = _argstr(key)
    sbuf += [key.length].pack("N") + key
    rnum += 1
  end
  sbuf = [0xC8, 0x31, rnum].pack("CCN") + sbuf
  if !_send(sbuf)
    @ecode = ESEND
    return -1
  end
  code = _recvcode
  rnum = _recvint32
  if code == -1
    @ecode = ERECV
    return -1
  end
  if code != 0
    @ecode = ENOREC
    return -1
  end
  if rnum < 0
    @ecode = ERECV
    return -1
  end
  recs.clear
  for i in 1..rnum
    ksiz = _recvint32()
    vsiz = _recvint32()
    if ksiz < 0 || vsiz < 0
      @ecode = ERECV
      return -1
    end
    kbuf = _recv(ksiz)
    vbuf = _recv(vsiz)
    if !kbuf || !vbuf
      @ecode = ERECV
      return -1
    end
    recs[kbuf] = _retstr(vbuf)
  end
  return rnum
end

misc

public misc(name, args = [], opts = 0)

Call a versatile function for miscellaneous operations.%% `name’ specifies the name of the function. All databases support "putlist", "outlist", and "getlist". "putlist" is to store records. It receives keys and values one after the other, and returns an empty list. "outlist" is to remove records. It receives keys, and returns an empty array. "getlist" is to retrieve records. It receives keys, and returns keys and values of corresponding records one after the other. Table database supports "setindex", "search", and "genuid".%% `args’ specifies an array containing arguments. If it is not defined, no argument is specified.%% `opts’ specifies options by bitwise-or: `TokyoTyrant::RDB::MONOULOG’ for omission of the update log. If it is not defined, no option is specified.%% If successful, the return value is an array of the result. `nil’ is returned on failure.%%

[View source]


832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
# File 'lib/tokyotyrant.rb', line 832

def misc(name, args = [], opts = 0)
  name = _argstr(name)
  args = Array::new if !args.is_a?(Array)
  opts = _argnum(opts)
  if !@sock
    @ecode = EINVALID
    return nil
  end
  sbuf = [0xC8, 0x90, name.length, opts, args.size].pack("CCNNN")
  sbuf += name
  args.each do |arg|
    arg = _argstr(arg)
    sbuf += [arg.length].pack("N") + arg
  end
  if !_send(sbuf)
    @ecode = ESEND
    return nil
  end
  code = _recvcode
  rnum = _recvint32
  if code == -1
    @ecode = ERECV
    return nil
  end
  if code != 0
    @ecode = EMISC
    return nil
  end
  res = Array::new
  for i in 1..rnum
    esiz = _recvint32
    if esiz < 0
      @ecode = ERECV
      return nil
    end
    ebuf = _recv(esiz)
    if !ebuf
      @ecode = ERECV
      return nil
    end
    res.push(_retstr(ebuf))
  end
  return res
end

open

public open(host, port = 0)

Open a remote database connection.%% `host’ specifies the name or the address of the server.%% `port’ specifies the port number. If it is not defined or not more than 0, UNIX domain socket is used and the path of the socket file is specified by the host parameter.%% If successful, the return value is true, else, it is false.%%

[View source]


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/tokyotyrant.rb', line 99

def open(host, port = 0)
  host = _argstr(host)
  port = _argnum(port)
  if @sock
    @ecode = EINVALID
    return false
  end
  if port > 0
    begin
      info = TCPSocket.gethostbyname(host)
    rescue Exception
      @ecode = ENOHOST
      return false
    end
    begin
      sock = TCPSocket.open(info[3], port)
    rescue Exception
      @ecode = EREFUSED
      return false
    end
    begin
      sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true)
    rescue Exception
    end
  else
    begin
      sock = UNIXSocket.open(host)
    rescue Exception
      @ecode = EREFUSED
      return false
    end
  end
  if sock.respond_to?(:set_encoding)
    sock.set_encoding("ASCII-8BIT")
  end
  @sock = sock
  return true
end

optimize

public optimize(params = nil)

Optimize the storage.%% `params’ specifies the string of the tuning parameters. If it is not defined, it is not used.%% If successful, the return value is true, else, it is false.%%

[View source]


665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
# File 'lib/tokyotyrant.rb', line 665

def optimize(params = nil)
  params = params ? _argstr(params) : ""
  if !@sock
    @ecode = EINVALID
    return false
  end
  sbuf = [0xC8, 0x71, params.length].pack("CCN")
  sbuf += params
  if !_send(sbuf)
    @ecode = ESEND
    return false
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return false
  end
  if code != 0
    @ecode = EMISC
    return false
  end
  return true
end

out

public out(key)

Remove a record.%% `key’ specifies the key.%% If successful, the return value is true, else, it is false.%%

[View source]


295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/tokyotyrant.rb', line 295

def out(key)
  key = _argstr(key)
  if !@sock
    @ecode = EINVALID
    return false
  end
  sbuf = [0xC8, 0x20, key.length].pack("CCN")
  sbuf += key
  if !_send(sbuf)
    @ecode = ESEND
    return false
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return false
  end
  if code != 0
    @ecode = ENOREC
    return false
  end
  return true
end

put

public put(key, value)

Store a record.%% `key’ specifies the key.%% `value’ specifies the value.%% 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.%%

[View source]


159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/tokyotyrant.rb', line 159

def put(key, value)
  key = _argstr(key)
  value = _argstr(value)
  if !@sock
    @ecode = EINVALID
    return false
  end
  sbuf = [0xC8, 0x10, key.length, value.length].pack("CCNN")
  sbuf += key + value
  if !_send(sbuf)
    @ecode = ESEND
    return false
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return false
  end
  if code != 0
    @ecode = EMISC
    return false
  end
  return true
end

putcat

public putcat(key, value)

Concatenate a value at the end of the existing record.%% `key’ specifies the key.%% `value’ specifies the value.%% If successful, the return value is true, else, it is false.%% If there is no corresponding record, a new record is created.%%

[View source]


217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/tokyotyrant.rb', line 217

def putcat(key, value)
  key = _argstr(key)
  value = _argstr(value)
  if !@sock
    @ecode = EINVALID
    return false
  end
  sbuf = [0xC8, 0x12, key.length, value.length].pack("CCNN")
  sbuf += key + value
  if !_send(sbuf)
    @ecode = ESEND
    return false
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return false
  end
  if code != 0
    @ecode = EMISC
    return false
  end
  return true
end

putkeep

public putkeep(key, value)

Store a new record.%% `key’ specifies the key.%% `value’ specifies the value.%% 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.%%

[View source]


188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/tokyotyrant.rb', line 188

def putkeep(key, value)
  key = _argstr(key)
  value = _argstr(value)
  if !@sock
    @ecode = EINVALID
    return false
  end
  sbuf = [0xC8, 0x11, key.length, value.length].pack("CCNN")
  sbuf += key + value
  if !_send(sbuf)
    @ecode = ESEND
    return false
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return false
  end
  if code != 0
    @ecode = EKEEP
    return false
  end
  return true
end

putnr

public putnr(key, value)

Store a record without response from the server.%% `key’ specifies the key.%% `value’ specifies the value.%% 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.%%

[View source]


277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/tokyotyrant.rb', line 277

def putnr(key, value)
  key = _argstr(key)
  value = _argstr(value)
  if !@sock
    @ecode = EINVALID
    return false
  end
  sbuf = [0xC8, 0x18, key.length, value.length].pack("CCNN")
  sbuf += key + value
  if !_send(sbuf)
    @ecode = ESEND
    return false
  end
  return true
end

putshl

public putshl(key, value, width = 0)

Concatenate a value at the end of the existing record and shift it to the left.%% `key’ specifies the key.%% `value’ specifies the value.%% `width’ specifies the width of the record.%% If successful, the return value is true, else, it is false.%% If there is no corresponding record, a new record is created.%%

[View source]


247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/tokyotyrant.rb', line 247

def putshl(key, value, width = 0)
  key = _argstr(key)
  value = _argstr(value)
  width = _argnum(width)
  if !@sock
    @ecode = EINVALID
    return false
  end
  sbuf = [0xC8, 0x13, key.length, value.length, width].pack("CCNNN")
  sbuf += key + value
  if !_send(sbuf)
    @ecode = ESEND
    return false
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return false
  end
  if code != 0
    @ecode = EMISC
    return false
  end
  return true
end

rnum

public rnum

Get the number of records.%% The return value is the number of records or 0 if the object does not connect to any database server.%%

[View source]


740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'lib/tokyotyrant.rb', line 740

def rnum()
  if !@sock
    @ecode = EINVALID
    return 0
  end
  sbuf = [0xC8, 0x80].pack("CC")
  if !_send(sbuf)
    @ecode = ESEND
    return 0
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return 0
  end
  if code != 0
    @ecode = EMISC
    return 0
  end
  rv = _recvint64
  if rv < 0
    @ecode = ERECV
    return 0
  end
  return rv
end

size

public size

Get the size of the database.%% The return value is the size of the database or 0 if the object does not connect to any database server.%%

[View source]


768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# File 'lib/tokyotyrant.rb', line 768

def size()
  if !@sock
    @ecode = EINVALID
    return 0
  end
  sbuf = [0xC8, 0x81].pack("CC")
  if !_send(sbuf)
    @ecode = ESEND
    return 0
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return 0
  end
  if code != 0
    @ecode = EMISC
    return 0
  end
  rv = _recvint64
  if rv < 0
    @ecode = ERECV
    return 0
  end
  return rv
end

stat

public stat

Get the status string of the database server.%% The return value is the status message of the database or `nil’ if the object does not connect to any database server. The message format is TSV. The first field of each line means the parameter name and the second field means the value.%%

[View source]


796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
# File 'lib/tokyotyrant.rb', line 796

def stat()
  if !@sock
    @ecode = EINVALID
    return nil
  end
  sbuf = [0xC8, 0x88].pack("CC")
  if !_send(sbuf)
    @ecode = ESEND
    return nil
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return nil
  end
  if code != 0
    @ecode = ENOREC
    return nil
  end
  ssiz = _recvint32
  if ssiz < 0
    @ecode = ERECV
    return nil
  end
  sbuf = _recv(ssiz)
  if !sbuf
    @ecode = ERECV
    return nil
  end
  return _retstr(sbuf)
end

store

public store(key, value)

Hash-compatible method.%% Alias of `put’.%%

[View source]


882
883
884
# File 'lib/tokyotyrant.rb', line 882

def store(key, value)
  return put(key, value)
end

sync

public sync

Synchronize updated contents with the file and the device.%% If successful, the return value is true, else, it is false.%%

[View source]


641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/tokyotyrant.rb', line 641

def sync()
  if !@sock
    @ecode = EINVALID
    return false
  end
  sbuf = [0xC8, 0x70].pack("CC")
  if !_send(sbuf)
    @ecode = ESEND
    return false
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return false
  end
  if code != 0
    @ecode = EMISC
    return false
  end
  return true
end

values

public values

Hash-compatible method.%% Get an array of all keys.%%

[View source]


980
981
982
983
984
985
986
987
988
989
# File 'lib/tokyotyrant.rb', line 980

def values
  tvals = Array::new
  return tvals if !iterinit
  while key = iternext
    value = get(key)
    break if !value
    tvals.push(value)
  end
  return tvals
end

vanish

public vanish

Remove all records.%% If successful, the return value is true, else, it is false.%%

[View source]


690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
# File 'lib/tokyotyrant.rb', line 690

def vanish()
  if !@sock
    @ecode = EINVALID
    return false
  end
  sbuf = [0xC8, 0x72].pack("CC")
  if !_send(sbuf)
    @ecode = ESEND
    return false
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return false
  end
  if code != 0
    @ecode = EMISC
    return false
  end
  return true
end

vsiz

public vsiz(key)

Get the size of the value of a record.%% `key’ specifies the key.%% If successful, the return value is the size of the value of the corresponding record, else, it is -1.%%

[View source]


406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/tokyotyrant.rb', line 406

def vsiz(key)
  key = _argstr(key)
  if !@sock
    @ecode = EINVALID
    return -1
  end
  sbuf = [0xC8, 0x38, key.length].pack("CCN")
  sbuf += key
  if !_send(sbuf)
    @ecode = ESEND
    return -1
  end
  code = _recvcode
  if code == -1
    @ecode = ERECV
    return -1
  end
  if code != 0
    @ecode = ENOREC
    return -1
  end
  return _recvint32
end
Generated on Friday, September 18 2009 at 10:35:42 AM by YARD 0.2.3.5 (ruby-1.8.7).