Method: Memcached#set
- Defined in:
- lib/memcached/memcached.rb
#set(key, value, ttl = @default_ttl, marshal = true, flags = FLAGS) ⇒ Object
Set a key/value pair. Accepts a String key and an arbitrary Ruby object. Overwrites any existing value on the server.
Accepts an optional ttl value to specify the maximum lifetime of the key on the server. ttl can be either an integer number of seconds, or a Time elapsed time object. 0 means no ttl. Note that there is no guarantee that the key will persist as long as the ttl, but it will not persist longer.
Also accepts a marshal value, which defaults to true. Set marshal to false if you want the value to be set directly.
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/memcached/memcached.rb', line 308 def set(key, value, ttl=@default_ttl, marshal=true, flags=FLAGS) value = marshal ? Marshal.dump(value) : value.to_s begin check_return_code( Lib.memcached_set(@struct, key, value, ttl, flags), key ) rescue => e tries ||= 0 retry if e.instance_of?(ClientError) && !tries raise unless tries < [:exception_retry_limit] && should_retry(e) tries += 1 retry end end |