349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
# File 'ext/native_server.c', line 349
static VALUE mc_cas(int argc, VALUE *argv, VALUE self) {
memcached_st *mc;
VALUE key, value, cas, expiry, flags;
static memcached_return_t result;
Data_Get_Struct(self, memcached_st, mc);
rb_scan_args(argc, argv, "32", &key, &value, &cas, &expiry, &flags);
key = StringValue(key);
if (!use_binary(mc)) key = escape_key(key, NULL);
value = StringValue(value);
result = memcached_cas(mc, RSTRING_PTR(key), RSTRING_LEN(key), RSTRING_PTR(value), RSTRING_LEN(value),
RTEST(expiry) ? NUM2UINT(expiry) : 0,
RTEST(flags) ? NUM2UINT(flags) : 0,
NUM2ULL(cas));
if (result == MEMCACHED_SUCCESS) {
return value;
} else if (result == MEMCACHED_NOTFOUND || result == MEMCACHED_DATA_EXISTS) {
return Qnil;
} else {
return throw_error(&result);
}
}
|