class Aerospike::Exp

Constants

ABS
ADD
AND
BIN
BIN_TYPE
CALL
CEIL
COND
DEVICE_SIZE
DIGEST_MODULO
DIV
EQ
EXCLUSIVE
FLOOR
GE
GEO
GT
INT_AND
INT_ARSHIFT
INT_COUNT
INT_LSCAN
INT_LSHIFT
INT_NOT
INT_OR
INT_RSCAN
INT_RSHIFT
INT_XOR
IS_TOMBSTONE
KEY
KEY_EXISTS
LAST_UPDATE
LE
LET
LOG
LT
MAX
MEMORY_SIZE
MIN
MOD
MODIFY
MUL
NANOS_PER_MILLIS
NE
NOT
OR
POW
QUOTED
RECORD_SIZE
REGEX
SET_NAME
SINCE_UPDATE
SUB
TO_FLOAT
TO_INT
TTL
UNKNOWN
VAR
VOID_TIME

Public Class Methods

abs(value) click to toggle source

Create operator that returns absolute value of a number. All arguments must resolve to integer or float. Requires server version 5.6.0+.

Examples

# abs(a) == 1
Exp.eq(
  Exp.abs(Exp.int_bin("a")),
  Exp.int_val(1))
# File lib/aerospike/exp/exp.rb, line 652
def self.abs(value)
  CmdExp.new(ABS, value)
end
add(*exps) click to toggle source

Create “add” (+) operator that applies to a variable number of expressions. Return sum of all arguments. All arguments must resolve to the same type (or float). Requires server version 5.6.0+.

Examples

# a + b + c == 10
Exp.eq(
  Exp.add(Exp.int_bin("a"), Exp.int_bin("b"), Exp.int_bin("c")),
  Exp.int_val(10))
# File lib/aerospike/exp/exp.rb, line 556
def self.add(*exps)
  CmdExp.new(ADD, *exps)
end
and(*exps) click to toggle source

Create “and” (&&) operator that applies to a variable number of expressions.

Examples

# (a > 5 || a == 0) && b < 3
Exp.and(
  Exp.or(
    Exp.gt(Exp.int_bin("a"), Exp.val(5)),
    Exp.eq(Exp.int_bin("a"), Exp.val(0))),
  Exp.lt(Exp.int_bin("b"), Exp.val(3)))
# File lib/aerospike/exp/exp.rb, line 462
def self.and(*exps)
  CmdExp.new(AND, *exps)
end
arshift(value, shift) click to toggle source

Create integer “arithmetic right shift” (>>) operator. Requires server version 5.6.0+.

Examples

# a >> 8 > 0xff
Exp.gt(
  Exp.arshift(Exp.int_bin("a"), Exp.val(8)),
  Exp.val(0xff))
# File lib/aerospike/exp/exp.rb, line 787
def self.arshift(value, shift)
  CmdExp.new(INT_ARSHIFT, value, shift)
end
bin(name, type) click to toggle source

Create bin expression of specified type.

Examples

# String bin "a" == "views"
Exp.eq(Exp.bin("a", Type::STRING), Exp.str_val("views"))
# File lib/aerospike/exp/exp.rb, line 119
def self.bin(name, type)
  Bin.new(name, type)
end
bin_exists(name) click to toggle source

Create expression that returns if bin of specified name exists.

Examples

# Bin "a" exists in record
Exp.bin_exists("a")
# File lib/aerospike/exp/exp.rb, line 212
def self.bin_exists(name)
  Exp.ne(Exp.bin_type(name), Exp.int_val(0))
end
bin_type(name) click to toggle source
Create expression that returns bin’s integer particle type

See {ParticleType}.

Examples

# Bin "a" particle type is a list
Exp.eq(Exp.bin_type("a"), Exp.val(ParticleType::LIST))
# File lib/aerospike/exp/exp.rb, line 222
def self.bin_type(name)
  CmdStr.new(BIN_TYPE, name)
end
blob_bin(name) click to toggle source

Create bin expression.

Examples

# Blob bin "a" == [1,2,3]
Exp.eq(Exp.blob_bin("a"), Exp.val(new {1, 2, 3}))
# File lib/aerospike/exp/exp.rb, line 164
def self.blob_bin(name)
  Bin.new(name, Type::BLOB)
end
blob_val(val) click to toggle source

Create blob byte value.

# File lib/aerospike/exp/exp.rb, line 408
def self.blob_val(val)
  Blob.new(val)
end
bool_bin(name) click to toggle source

Create boolean bin expression.

Examples

# Boolean bin "a" == true
Exp.eq(Exp.bool_bin("a"), Exp.val(true))
# File lib/aerospike/exp/exp.rb, line 155
def self.bool_bin(name)
  Bin.new(name, Type::BOOL)
end
bool_val(val) click to toggle source

Create boolean value.

# File lib/aerospike/exp/exp.rb, line 388
def self.bool_val(val)
  Bool.new(val)
end
ceil(num) click to toggle source

Create expression that rounds a floating point number up to the closest integer value. The return type is float. Requires server version 5.6.0+.

Examples

# ceil(2.15) >= 3.0
Exp.ge(
  Exp.ceil(Exp.val(2.15)),
  Exp.val(3.0))
# File lib/aerospike/exp/exp.rb, line 676
def self.ceil(num)
  CmdExp.new(CEIL, num)
end
cond(*exps) click to toggle source

Conditionally select an expression from a variable number of expression pairs followed by default expression action. Requires server version 5.6.0+.

Examples

Args Format: bool exp1, action exp1, bool exp2, action exp2, …, action-default

# Apply operator based on type

Exp.cond(

Exp.eq(Exp.int_bin("type"), Exp.val(0)), Exp.add(Exp.int_bin("val1"), Exp.int_bin("val2")),
Exp.eq(Exp.int_bin("type"), Exp.int_val(1)), Exp.sub(Exp.int_bin("val1"), Exp.int_bin("val2")),
Exp.eq(Exp.int_bin("type"), Exp.val(2)), Exp.mul(Exp.int_bin("val1"), Exp.int_bin("val2")),
Exp.val(-1))
# File lib/aerospike/exp/exp.rb, line 877
def self.cond(*exps)
  CmdExp.new(COND, *exps)
end
count(exp) click to toggle source

Create expression that returns count of integer bits that are set to 1. Requires server version 5.6.0+.

Examples

# count(a) == 4
Exp.eq(
  Exp.count(Exp.int_bin("a")),
  Exp.val(4))
# File lib/aerospike/exp/exp.rb, line 799
def self.count(exp)
  CmdExp.new(INT_COUNT, exp)
end
def(name, value) click to toggle source

Assign variable to a {Exp#let(Exp…)} expression that can be accessed later. Requires server version 5.6.0+.

Examples

# 5 < a < 10 Exp.let(

Exp.def("x", Exp.int_bin("a")),
Exp.and(
  Exp.lt(Exp.val(5), Exp.var("x")),
  Exp.lt(Exp.var("x"), Exp.int_val(10))))
# File lib/aerospike/exp/exp.rb, line 910
def self.def(name, value)
  Def.new(name, value)
end
device_size() click to toggle source

Create expression that returns record size on disk. If server storage-engine is memory, then zero is returned. This expression usually evaluates quickly because record meta data is cached in memory.

Examples

# Record device size >= 100 KB
Exp.ge(Exp.device_size, Exp.int_val(100 * 1024))
# File lib/aerospike/exp/exp.rb, line 261
def self.device_size
  Cmd.new(DEVICE_SIZE)
end
digest_modulo(mod) click to toggle source

Create expression that returns record digest modulo as integer. This expression usually evaluates quickly because record meta data is cached in memory.

Examples

# Records that have digest(key) % 3 == 1
Exp.eq(Exp.digest_modulo(3), Exp.int_val(1))
# File lib/aerospike/exp/exp.rb, line 338
def self.digest_modulo(mod)
  CmdInt.new(DIGEST_MODULO, mod)
end
div(*exps) click to toggle source

Create “divide” (/) operator that applies to a variable number of expressions. If there is only one argument, returns the reciprocal for that argument. Otherwise, return the first argument divided by the product of the rest. All arguments must resolve to the same type (or float). Requires server version 5.6.0+.

Examples

# a / b / c > 1
Exp.gt(
  Exp.div(Exp.int_bin("a"), Exp.int_bin("b"), Exp.int_bin("c")),
  Exp.int_val(1))
# File lib/aerospike/exp/exp.rb, line 600
def self.div(*exps)
  CmdExp.new(DIV, *exps)
end
eq(left, right) click to toggle source

Create equal (==) expression.

Examples

# a == 11
Exp.eq(Exp.int_bin("a"), Exp.int_val(11))
# File lib/aerospike/exp/exp.rb, line 494
def self.eq(left, right)
  CmdExp.new(EQ, left, right)
end
exclusive(*exps) click to toggle source

Create expression that returns true if only one of the expressions are true. Requires server version 5.6.0+.

Examples

# exclusive(a == 0, b == 0)
Exp.exclusive(
  Exp.eq(Exp.int_bin("a"), Exp.val(0)),
  Exp.eq(Exp.int_bin("b"), Exp.val(0)))
# File lib/aerospike/exp/exp.rb, line 485
def self.exclusive(*exps)
  CmdExp.new(EXCLUSIVE, *exps)
end
float_bin(name) click to toggle source

Create 64 bit float bin expression.

Examples

# Float bin "a" >= 1.5
Exp.ge(Exp.float_bin("a"), Exp.int_val(1.5))
# File lib/aerospike/exp/exp.rb, line 137
def self.float_bin(name)
  Bin.new(name, Type::FLOAT)
end
float_val(val) click to toggle source

Create 64 bit floating point value.

# File lib/aerospike/exp/exp.rb, line 398
def self.float_val(val)
  Float.new(val)
end
floor(num) click to toggle source

Create expression that rounds a floating point number down to the closest integer value. The return type is float. Requires server version 5.6.0+.

Examples

# floor(2.95) == 2.0
Exp.eq(
  Exp.floor(Exp.val(2.95)),
  Exp.val(2.0))
# File lib/aerospike/exp/exp.rb, line 664
def self.floor(num)
  CmdExp.new(FLOOR, num)
end
ge(left, right) click to toggle source

Create greater than or equal (>=) operation.

Examples

# a >= 88
Exp.ge(Exp.int_bin("a"), Exp.val(88))
# File lib/aerospike/exp/exp.rb, line 521
def self.ge(left, right)
  CmdExp.new(GE, left, right)
end
geo(val) click to toggle source

Create geospatial json string value.

# File lib/aerospike/exp/exp.rb, line 379
def self.geo(val)
  Geo.new(val)
end
geo_bin(name) click to toggle source

Create geospatial bin expression.

Examples

# Geo bin "a" == region
String region = "{ \"type\": \"AeroCircle\", \"coordinates\": [[-122.0, 37.5], 50000.0] }"
Exp.geo_compare(Exp.geo_bin("loc"), Exp.geo(region))
# File lib/aerospike/exp/exp.rb, line 174
def self.geo_bin(name)
  Bin.new(name, Type::GEO)
end
geo_compare(left, right) click to toggle source

Create compare geospatial operation.

Examples

# Query region within coordinates.

region =
   "{ " +
   "  \"type\": \"Polygon\", " +
   "  \"coordinates\": [ " +
   "    [[-122.500000, 37.000000],[-121.000000, 37.000000], " +
   "     [-121.000000, 38.080000],[-122.500000, 38.080000], " +
   "     [-122.500000, 37.000000]] " +
   "    ] " +
   "}"
   Exp.geo_compare(Exp.geo_bin("a"), Exp.geo(region))
# File lib/aerospike/exp/exp.rb, line 374
def self.geo_compare(left, right)
  CmdExp.new(GEO, left, right)
end
gt(left, right) click to toggle source

Create greater than (>) operation.

Examples

# a > 8
Exp.gt(Exp.int_bin("a"), Exp.val(8))
# File lib/aerospike/exp/exp.rb, line 512
def self.gt(left, right)
  CmdExp.new(GT, left, right)
end
hll_bin(name) click to toggle source

Create hll bin expression.

Examples

# HLL bin “a” count > 7 Exp.gt(HLLExp.get_count(Exp.hll_bin(“a”)), Exp.val(7))

# File lib/aerospike/exp/exp.rb, line 203
def self.hll_bin(name)
  Bin.new(name, Type::HLL)
end
infinity_val() click to toggle source

Create Infinity value.

# File lib/aerospike/exp/exp.rb, line 428
def self.infinity_val
  Infinity.new
end
int_and(*exps) click to toggle source

Create integer “and” (&) operator that is applied to two or more integers. All arguments must resolve to integers. Requires server version 5.6.0+.

Examples

# a & 0xff == 0x11
Exp.eq(
  Exp.int_and(Exp.int_bin("a"), Exp.val(0xff)),
  Exp.val(0x11))
# File lib/aerospike/exp/exp.rb, line 713
def self.int_and(*exps)
  CmdExp.new(INT_AND, *exps)
end
int_bin(name) click to toggle source

Create 64 bit integer bin expression.

Examples

# Integer bin "a" == 200
Exp.eq(Exp.int_bin("a"), Exp.val(200))
# File lib/aerospike/exp/exp.rb, line 128
def self.int_bin(name)
  Bin.new(name, Type::INT)
end
int_not(exp) click to toggle source

Create integer “not” (~) operator. Requires server version 5.6.0+.

Examples

# ~a == 7
Exp.eq(
  Exp.int_not(Exp.int_bin("a")),
  Exp.val(7))
# File lib/aerospike/exp/exp.rb, line 751
def self.int_not(exp)
  CmdExp.new(INT_NOT, exp)
end
int_or(*exps) click to toggle source

Create integer “or” (|) operator that is applied to two or more integers. All arguments must resolve to integers. Requires server version 5.6.0+.

Examples

# a | 0x10 != 0
Exp.ne(
  Exp.int_or(Exp.int_bin("a"), Exp.val(0x10)),
  Exp.val(0))
# File lib/aerospike/exp/exp.rb, line 726
def self.int_or(*exps)
  CmdExp.new(INT_OR, *exps)
end
int_val(val) click to toggle source

Create 64 bit integer value.

# File lib/aerospike/exp/exp.rb, line 393
def self.int_val(val)
  Int.new(val)
end
int_xor(*exps) click to toggle source

Create integer “xor” (^) operator that is applied to two or more integers. All arguments must resolve to integers. Requires server version 5.6.0+.

Examples

# a ^ b == 16
Exp.eq(
  Exp.int_xor(Exp.int_bin("a"), Exp.int_bin("b")),
  Exp.int_val(16))
# File lib/aerospike/exp/exp.rb, line 739
def self.int_xor(*exps)
  CmdExp.new(INT_XOR, *exps)
end
is_tombstone() click to toggle source

Create expression that returns if record has been deleted and is still in tombstone state. This expression usually evaluates quickly because record meta data is cached in memory.

Examples

# Deleted records that are in tombstone state.
Exp.is_tombstone
# File lib/aerospike/exp/exp.rb, line 328
def self.is_tombstone
  Cmd.new(IS_TOMBSTONE)
end
key(type) click to toggle source

Create record key expression of specified type.

Examples

# Integer record key >= 100000 Exp.ge(Exp.key(Type::INT), Exp.int_val(100000))

# File lib/aerospike/exp/exp.rb, line 94
def self.key(type)
  CmdInt.new(KEY, type)
end
key_exists() click to toggle source

Create expression that returns if the primary key is stored in the record meta data as a boolean expression. This would occur when {Policy#send_key} is true on record write. This expression usually evaluates quickly because record meta data is cached in memory.

Examples

# Key exists in record meta data
Exp.key_exists
# File lib/aerospike/exp/exp.rb, line 106
def self.key_exists
  Cmd.new(KEY_EXISTS)
end
last_update() click to toggle source

Create expression that returns record last update time expressed as 64 bit integer nanoseconds since 1970-01-01 epoch. This expression usually evaluates quickly because record meta data is cached in memory.

Examples

# Record last update time >= 2020-01-15
Exp.ge(Exp.last_update, Exp.val(new GregorianCalendar(2020, 0, 15)))
# File lib/aerospike/exp/exp.rb, line 285
def self.last_update
  Cmd.new(LAST_UPDATE)
end
le(left, right) click to toggle source

Create less than or equals (<=) operation.

Examples

# a <= 1
Exp.le(Exp.int_bin("a"), Exp.int_val(1))
# File lib/aerospike/exp/exp.rb, line 539
def self.le(left, right)
  CmdExp.new(LE, left, right)
end
let(*exps) click to toggle source

Define variables and expressions in scope. Requires server version 5.6.0+.

Examples

Args Format: <def1>, <def2>, …, <exp> def: {Exp#def(String, Exp)} exp: Scoped expression

Examples

# 5 < a < 10 Exp.let(

Exp.def("x", Exp.int_bin("a")),
Exp.and(
  Exp.lt(Exp.val(5), Exp.var("x")),
  Exp.lt(Exp.var("x"), Exp.int_val(10))))
# File lib/aerospike/exp/exp.rb, line 896
def self.let(*exps)
  Let.new(exps)
end
list_bin(name) click to toggle source

Create list bin expression.

Examples

# Bin a[2] == 3
Exp.eq(ListExp.get_by_index(ListReturnType::VALUE, Type::INT, Exp.val(2), Exp.list_bin("a")), Exp.val(3))
# File lib/aerospike/exp/exp.rb, line 183
def self.list_bin(name)
  Bin.new(name, Type::LIST)
end
list_val(*list) click to toggle source

Create list value.

# File lib/aerospike/exp/exp.rb, line 413
def self.list_val(*list)
  ListVal.new(list)
end
log(num, base) click to toggle source

Create “log” operator for logarithm of “num” with base “base”. All arguments must resolve to floats. Requires server version 5.6.0+.

Examples

# log(a, 2.0) == 4.0
Exp.eq(
  Exp.log(Exp.float_bin("a"), Exp.val(2.0)),
  Exp.val(4.0))
# File lib/aerospike/exp/exp.rb, line 626
def self.log(num, base)
  CmdExp.new(LOG, num, base)
end
lscan(value, search) click to toggle source

Create expression that scans integer bits from left (most significant bit) to right (least significant bit), looking for a search bit value. When the search value is found, the index of that bit (where the most significant bit is index 0) is returned. If “search” is true, the scan will search for the bit value 1. If “search” is false it will search for bit value 0. Requires server version 5.6.0+.

Examples

# lscan(a, true) == 4
Exp.eq(
  Exp.lscan(Exp.int_bin("a"), Exp.val(true)),
  Exp.val(4))
# File lib/aerospike/exp/exp.rb, line 815
def self.lscan(value, search)
  CmdExp.new(INT_LSCAN, value, search)
end
lshift(value, shift) click to toggle source

Create integer “left shift” (<<) operator. Requires server version 5.6.0+.

Examples

# a << 8 > 0xff
Exp.gt(
  Exp.lshift(Exp.int_bin("a"), Exp.val(8)),
  Exp.val(0xff))
# File lib/aerospike/exp/exp.rb, line 763
def self.lshift(value, shift)
  CmdExp.new(INT_LSHIFT, value, shift)
end
lt(left, right) click to toggle source

Create less than (<) operation.

Examples

# a < 1000
Exp.lt(Exp.int_bin("a"), Exp.int_val(1000))
# File lib/aerospike/exp/exp.rb, line 530
def self.lt(left, right)
  CmdExp.new(LT, left, right)
end
map_bin(name) click to toggle source

Create map bin expression.

Examples

# Bin a["key"] == "value"
Exp.eq(
  MapExp.get_by_key(MapReturnType::VALUE, Type::STRING, Exp.str_val("key"), Exp.map_bin("a")),
  Exp.str_val("value"))
# File lib/aerospike/exp/exp.rb, line 194
def self.map_bin(name)
  Bin.new(name, Type::MAP)
end
map_val(map) click to toggle source

Create map value.

# File lib/aerospike/exp/exp.rb, line 418
def self.map_val(map)
  MapVal.new(map)
end
max(*exps) click to toggle source

Create expression that returns the maximum value in a variable number of expressions. All arguments must be the same type (or float). Requires server version 5.6.0+.

Examples

# max(a, b, c) > 100
Exp.gt(
  Exp.max(Exp.int_bin("a"), Exp.int_bin("b"), Exp.int_bin("c")),
  Exp.int_val(100))
# File lib/aerospike/exp/exp.rb, line 857
def self.max(*exps)
  CmdExp.new(MAX, *exps)
end
memory_size() click to toggle source

Create expression that returns record size in memory. If server storage-engine is not memory nor data-in-memory, then zero is returned. This expression usually evaluates quickly because record meta data is cached in memory.

Requires server version 5.3.0+

Examples

# Record memory size >= 100 KB
Exp.ge(Exp.memory_size, Exp.int_val(100 * 1024))
# File lib/aerospike/exp/exp.rb, line 274
def self.memory_size
  Cmd.new(MEMORY_SIZE)
end
min(*exps) click to toggle source

Create expression that returns the minimum value in a variable number of expressions. All arguments must be the same type (or float). Requires server version 5.6.0+.

Examples

# min(a, b, c) > 0
Exp.gt(
  Exp.min(Exp.int_bin("a"), Exp.int_bin("b"), Exp.int_bin("c")),
  Exp.val(0))
# File lib/aerospike/exp/exp.rb, line 844
def self.min(*exps)
  CmdExp.new(MIN, *exps)
end
mod(numerator, denominator) click to toggle source

Create “modulo” (%) operator that determines the remainder of “numerator” divided by “denominator”. All arguments must resolve to integers. Requires server version 5.6.0+.

Examples

# a % 10 == 0
Exp.eq(
  Exp.mod(Exp.int_bin("a"), Exp.int_val(10)),
  Exp.val(0))
# File lib/aerospike/exp/exp.rb, line 639
def self.mod(numerator, denominator)
  CmdExp.new(MOD, numerator, denominator)
end
mul(*exps) click to toggle source

Create “multiply” (*) operator that applies to a variable number of expressions. Return the product of all arguments. If only one argument is supplied, return that argument. All arguments must resolve to the same type (or float). Requires server version 5.6.0+.

Examples

# a * b * c < 100
Exp.lt(
  Exp.mul(Exp.int_bin("a"), Exp.int_bin("b"), Exp.int_bin("c")),
  Exp.int_val(100))
# File lib/aerospike/exp/exp.rb, line 585
def self.mul(*exps)
  CmdExp.new(MUL, *exps)
end
ne(left, right) click to toggle source

Create not equal (!=) expression

Examples

# a != 13
Exp.ne(Exp.int_bin("a"), Exp.int_val(13))
# File lib/aerospike/exp/exp.rb, line 503
def self.ne(left, right)
  CmdExp.new(NE, left, right)
end
nil_val() click to toggle source

Create nil value.

# File lib/aerospike/exp/exp.rb, line 423
def self.nil_val
  Nil.new
end
not(exp) click to toggle source

Create “not” operator expression.

Examples

# ! (a == 0 || a == 10)
Exp.not(
  Exp.or(
    Exp.eq(Exp.int_bin("a"), Exp.val(0)),
    Exp.eq(Exp.int_bin("a"), Exp.int_val(10))))
# File lib/aerospike/exp/exp.rb, line 449
def self.not(exp)
  CmdExp.new(NOT, exp)
end
or(*exps) click to toggle source

Create “or” (||) operator that applies to a variable number of expressions.

Examples

# a == 0 || b == 0
Exp.or(
  Exp.eq(Exp.int_bin("a"), Exp.val(0)),
  Exp.eq(Exp.int_bin("b"), Exp.val(0)))
# File lib/aerospike/exp/exp.rb, line 473
def self.or(*exps)
  CmdExp.new(OR, *exps)
end
pack(ctx, command, *vals) click to toggle source
# File lib/aerospike/exp/exp.rb, line 1048
def self.pack(ctx, command, *vals)
  Packer.use do |packer|
    # ctx is not support for bit commands
    packer.write_array_header(vals.to_a.length + 1)
    packer.write(command)
    vals.each do |v|
      if v.is_a?(Exp)
        v.pack(packer)
      else
        Value.of(v).pack(packer)
      end
    end
    return packer.bytes
  end
end
pack_ctx(packer, ctx) click to toggle source
# File lib/aerospike/exp/exp.rb, line 1064
def self.pack_ctx(packer, ctx)
  unless ctx.to_a.empty?
    packer.write_array_header(3)
    packer.write(0xff)
    packer.write_array_header(ctx.length * 2)

    ctx.each do |c|
      packer.write(c.id)
      c.value.pack(packer)
    end
  end
end
pow(base, exponent) click to toggle source

Create “power” operator that raises a “base” to the “exponent” power. All arguments must resolve to floats. Requires server version 5.6.0+.

Examples

# pow(a, 2.0) == 4.0
Exp.eq(
  Exp.pow(Exp.float_bin("a"), Exp.val(2.0)),
  Exp.val(4.0))
# File lib/aerospike/exp/exp.rb, line 613
def self.pow(base, exponent)
  CmdExp.new(POW, base, exponent)
end
record_size() click to toggle source

Create expression that returns the record size. This expression usually evaluates quickly because record meta data is cached in memory. Requires server version 7.0+. This expression replaces {#deviceSize()} and {#memorySize()} since those older expressions are equivalent on server version 7.0+.

{@code // Record size >= 100 KB Exp.ge(Exp.record_size(), Exp.val(100 * 1024)) }

# File lib/aerospike/exp/exp.rb, line 235
def self.record_size
  Cmd.new(RECORD_SIZE)
end
regex_compare(regex, flags, bin) click to toggle source

Create expression that performs a regex match on a string bin or string value expression.

Examples

# Select string bin “a” that starts with “prefix” and ends with “suffix”. # Ignore case and do not match newline. Exp.regex_compare(“prefix.*suffix”, RegexFlags.ICASE | RegexFlags.NEWLINE, Exp.str_bin(“a”))

@param regex regular expression string @param flags regular expression bit flags. See {Exp::RegexFlags} @param bin string bin or string value expression

# File lib/aerospike/exp/exp.rb, line 352
def self.regex_compare(regex, flags, bin)
  Regex.new(bin, regex, flags)
end
rscan(value, search) click to toggle source

Create expression that scans integer bits from right (least significant bit) to left (most significant bit), looking for a search bit value. When the search value is found, the index of that bit (where the most significant bit is index 0) is returned. If “search” is true, the scan will search for the bit value 1. If “search” is false it will search for bit value 0. Requires server version 5.6.0+.

Examples

# rscan(a, true) == 4
Exp.eq(
  Exp.rscan(Exp.int_bin("a"), Exp.val(true)),
  Exp.val(4))
# File lib/aerospike/exp/exp.rb, line 831
def self.rscan(value, search)
  CmdExp.new(INT_RSCAN, value, search)
end
rshift(value, shift) click to toggle source

Create integer “logical right shift” (>>>) operator. Requires server version 5.6.0+.

Examples

# a >>> 8 > 0xff
Exp.gt(
  Exp.rshift(Exp.int_bin("a"), Exp.val(8)),
  Exp.val(0xff))
# File lib/aerospike/exp/exp.rb, line 775
def self.rshift(value, shift)
  CmdExp.new(INT_RSHIFT, value, shift)
end
set_name() click to toggle source

Create expression that returns record set name string. This expression usually evaluates quickly because record meta data is cached in memory.

Examples

# Record set name == "myset"
Exp.eq(Exp.set_name, Exp.str_val("myset"))
# File lib/aerospike/exp/exp.rb, line 250
def self.set_name
  Cmd.new(SET_NAME)
end
since_update() click to toggle source

Create expression that returns milliseconds since the record was last updated. This expression usually evaluates quickly because record meta data is cached in memory.

Examples

# Record last updated more than 2 hours ago
Exp.gt(Exp.since_update, Exp.val(2 * 60 * 60 * 1000))
# File lib/aerospike/exp/exp.rb, line 295
def self.since_update
  Cmd.new(SINCE_UPDATE)
end
str_bin(name) click to toggle source

Create string bin expression.

Examples

# String bin "a" == "views"
Exp.eq(Exp.str_bin("a"), Exp.str_val("views"))
# File lib/aerospike/exp/exp.rb, line 146
def self.str_bin(name)
  Bin.new(name, Type::STRING)
end
str_val(val) click to toggle source

Create string value.

# File lib/aerospike/exp/exp.rb, line 403
def self.str_val(val)
  Str.new(val)
end
sub(*exps) click to toggle source

Create “subtract” (-) operator that applies to a variable number of expressions. If only one argument is provided, return the negation of that argument. Otherwise, return the sum of the 2nd to Nth argument subtracted from the 1st argument. All arguments must resolve to the same type (or float). Requires server version 5.6.0+.

Examples

# a - b - c > 10
Exp.gt(
  Exp.sub(Exp.int_bin("a"), Exp.int_bin("b"), Exp.int_bin("c")),
  Exp.int_val(10))
# File lib/aerospike/exp/exp.rb, line 571
def self.sub(*exps)
  CmdExp.new(SUB, *exps)
end
to_float(num) click to toggle source

Create expression that converts an integer to a float. Requires server version 5.6.0+.

Examples

# float(2) == 2.0
Exp.eq(
  Exp.to_float(Exp.val(2))),
  Exp.val(2.0))
# File lib/aerospike/exp/exp.rb, line 700
def self.to_float(num)
  CmdExp.new(TO_FLOAT, num)
end
to_int(num) click to toggle source

Create expression that converts a float to an integer. Requires server version 5.6.0+.

Examples

# int(2.5) == 2
Exp.eq(
  Exp.to_int(Exp.val(2.5)),
  Exp.val(2))
# File lib/aerospike/exp/exp.rb, line 688
def self.to_int(num)
  CmdExp.new(TO_INT, num)
end
ttl() click to toggle source

Create expression that returns record expiration time (time to live) in integer seconds. This expression usually evaluates quickly because record meta data is cached in memory.

Examples

# Record expires in less than 1 hour
Exp.lt(Exp.ttl, Exp.val(60 * 60))
# File lib/aerospike/exp/exp.rb, line 318
def self.ttl
  Cmd.new(TTL)
end
unknown() click to toggle source

Create unknown value. Used to intentionally fail an expression. The failure can be ignored with {Exp::WriteFlags#EVAL_NO_FAIL} or {Exp::ReadFlags#EVAL_NO_FAIL}. Requires server version 5.6.0+.

Examples

# double v = balance - 100.0 # return (v > 0.0)? v : unknown Exp.let(

Exp.def("v", Exp.sub(Exp.float_bin("balance"), Exp.int_val(100.0))),
Exp.cond(
  Exp.ge(Exp.var("v"), Exp.val(0.0)), Exp.var("v"),
  Exp.unknown))
# File lib/aerospike/exp/exp.rb, line 945
def self.unknown
  Cmd.new(UNKNOWN)
end
var(name) click to toggle source

Retrieve expression value from a variable. Requires server version 5.6.0+.

Examples

# 5 < a < 10 Exp.let(

Exp.def("x", Exp.int_bin("a")),
Exp.and(
  Exp.lt(Exp.val(5), Exp.var("x")),
  Exp.lt(Exp.var("x"), Exp.int_val(10))))
# File lib/aerospike/exp/exp.rb, line 924
def self.var(name)
  CmdStr.new(VAR, name)
end
void_time() click to toggle source

Create expression that returns record expiration time expressed as 64 bit integer nanoseconds since 1970-01-01 epoch. This expression usually evaluates quickly because record meta data is cached in memory.

Examples

# Record expires on 2021-01-01
Exp.and(
  Exp.ge(Exp.void_time, Exp.val(new GregorianCalendar(2021, 0, 1))),
  Exp.lt(Exp.void_time, Exp.val(new GregorianCalendar(2021, 0, 2))))
# File lib/aerospike/exp/exp.rb, line 308
def self.void_time
  Cmd.new(VOID_TIME)
end
wildcard_val() click to toggle source

Create Wildcard value.

# File lib/aerospike/exp/exp.rb, line 433
def self.wildcard_val
  Wildcard.new
end

Public Instance Methods

bytes() click to toggle source
# File lib/aerospike/exp/exp.rb, line 966
def bytes
  if @bytes.nil?
    Packer.use do |packer|
      pack(packer)
      @bytes = packer.bytes
    end
  end
  @bytes
end
size() click to toggle source

Estimate expression size in wire protocol. For internal use only.

# File lib/aerospike/exp/exp.rb, line 978
def size
  bytes.length
end
write(buf, offset) click to toggle source

Write expression in wire protocol. For internal use only.

# File lib/aerospike/exp/exp.rb, line 984
def write(buf, offset)
  buf.write_binary(bytes, offset)
end