Check and set a value in the minion datastore

    CLI Example:

    .. code-block:: bash

        salt '*' data.cas <key> <value> <old_value>
4824
def cas(key, value, old_value):
    '''
    
    '''
    store = load()
    if key not in store:
        return False

    if store[key] != old_value:
        return False

    store[key] = value
    dump(store)
    return True
981645
def set_(key, value, profile=None):
    '''
    
    '''
    if not profile:
        return False
    conn, cur, table = _connect(profile)
    if six.PY2:
        value = buffer(salt.utils.msgpack.packb(value))
    else:
        value = memoryview(salt.utils.msgpack.packb(value))
    q = profile.get('set_query', ('INSERT OR REPLACE INTO {0} VALUES '
                                  '(:key, :value)').format(table))
    conn.execute(q, {'key': key, 'value': value})
    conn.commit()
    return True
1044961
function setValue(name, stat, value, gran, timestamp, callback) {
        if(typeof gran == 'string') {
            gran = util.getUnitDesc(gran)
        }
        var key = getGranKey(name, gran, timestamp);
        redis.hset(key, stat, value, callback)
    }
532906
def set(option, value=(not_set=true), ignore_setter=false, &block)
      raise ArgumentError, 'value not set' if block and !not_set
      return self if !not_set and value.nil?

      if not_set
        set_options option
        return self
      end

      if respond_to?("#{option}=") and not ignore_setter
        return __send__("#{option}=", value)
      end

      define_accessors option, value
      self
    end
811961
def _call_set(self, command, value, *args, **kwargs):
        
        if self.indexable:
            current = self.proxy_get()
            if normalize(current) != normalize(value):
                if current is not None:
                    self.deindex(current)
                if value is not None:
                    self.index(value)
        return self._traverse_command(command, value, *args, **kwargs)
298316
def key_value(minion_id,
              pillar,  # pylint: disable=W0613
              pillar_key='redis_pillar'):
    '''
    
    '''
    # Identify key type and process as needed based on that type
    key_type = __salt__['redis.key_type'](minion_id)
    if key_type == 'string':
        return {pillar_key: __salt__['redis.get_key'](minion_id)}
    elif key_type == 'hash':
        return {pillar_key: __salt__['redis.hgetall'](minion_id)}
    elif key_type == 'list':
        list_size = __salt__['redis.llen'](minion_id)
        if not list_size:
            return {}
        return {pillar_key: __salt__['redis.lrange'](minion_id, 0,
                                                     list_size - 1)}
    elif key_type == 'set':
        return {pillar_key: __salt__['redis.smembers'](minion_id)}
    elif key_type == 'zset':
        set_size = __salt__['redis.zcard'](minion_id)
        if not set_size:
            return {}
        return {pillar_key: __salt__['redis.zrange'](minion_id, 0,
                                                     set_size - 1)}
    # Return nothing for unhandled types
    return {}
1099101
def set?(key)
      check_key!(key)
      expires!(key)
      @data.keys.include?(key.to_s)
    end
608916
def put_(keyname, val):
    '''
    
    '''
    mdata = _check_mdata_put()
    ret = {}

    if mdata:
        cmd = 'echo {2} | {0} {1}'.format(mdata, keyname, val)
        ret = __salt__['cmd.run_all'](cmd, python_shell=True, ignore_retcode=True)

    return ret['retcode'] == 0
39556
function setItem(key, value, callback) {
	        var self = this;

	        // Cast the key to a string, as that's all we can set as a key.
	        if (typeof key !== 'string') {
	            globalObject.console.warn(key + ' used as a key, but it is not a string.');
	            key = String(key);
	        }

	        var promise = self.ready().then(function () {
	            // Convert undefined values to null.
	            // https://github.com/mozilla/localForage/pull/42
	            if (value === undefined) {
	                value = null;
	            }

	            // Save the original value to pass to the callback.
	            var originalValue = value;

	            return new Promise(function (resolve, reject) {
	                var dbInfo = self._dbInfo;
	                dbInfo.serializer.serialize(value, function (value, error) {
	                    if (error) {
	                        reject(error);
	                    } else {
	                        try {
	                            localStorage.setItem(dbInfo.keyPrefix + key, value);
	                            resolve(originalValue);
	                        } catch (e) {
	                            // localStorage capacity exceeded.
	                            // TODO: Make this a specific error/event.
	                            if (e.name === 'QuotaExceededError' || e.name === 'NS_ERROR_DOM_QUOTA_REACHED') {
	                                reject(e);
	                            }
	                            reject(e);
	                        }
	                    }
	                });
	            });
	        });

	        executeCallback(promise, callback);
	        return promise;
	    }
727627
static public Value put( Key key, Value val, Futures fs, boolean dontCache ) {
    assert key != null;
    assert val==null || val._key == key:"non-matching keys " + key + " != " + val._key;
    while( true ) {
      Value old = Value.STORE_get(key); // Raw-get: do not lazy-manifest if overwriting
      Value res = DputIfMatch(key,val,old,fs,dontCache);
      if( res == old ) return old; // PUT is globally visible now?
      if( val != null && val._key != key ) key = val._key;
    }
  }
396164
def apply(key, value):
    '''
    
    '''
    path = __opts__['conf_file']
    if os.path.isdir(path):
        path = os.path.join(path, 'master')
    data = values()
    data[key] = value
    with salt.utils.files.fopen(path, 'w+') as fp_:
        salt.utils.yaml.safe_dump(data, default_flow_style=False)
1321356
def set(self, key, value=None, dir=False, refresh=False, ttl=None,
            prev_value=None, prev_index=None, prev_exist=None, timeout=None):
        """"""
        url = self.make_key_url(key)
        data = self.build_args({
            'value': (six.text_type, value),
            'dir': (bool, dir or None),
            'refresh': (bool, refresh or None),
            'ttl': (int, ttl),
            'prevValue': (six.text_type, prev_value),
            'prevIndex': (int, prev_index),
            'prevExist': (bool, prev_exist),
        })
        try:
            res = self.session.put(url, data=data, timeout=timeout)
        except:
            self.erred()
        return self.wrap_response(res)
1227397
def set(self, key, data, retry=0):

    

    try:

      if type(data) != dict:
        raise Exception("data needs to be of type <dict>")

      #t1 = time.time()

      if not data.has_key("_rev"):
        exists = self.bucket.get(key)
        if exists:
          data["_rev"] = exists.get("_rev")
      data["_id"] = key
      try:
        #print "Preparing save: %s %s" % (key, data)
        (id, rev) = self.bucket.save(data)
      except couchdb.http.ResourceConflict, inst:
        if retry > 0:
          if data.has_key("_rev"):
            del data["_rev"]
          retry -= 1
          return self.set(key, data, retry=retry)
        else:
          if self.logger:
            self.logger.error("Document update conflict '%s' on '%s', rev '%s'" % (inst, key, data.get("_rev")))
            return 0
          else:
            raise

      return rev

      #print "Saved in %.5f" % (time.time() - t1)
    except:
      raise
913408
def set(self, name, value):
        """"""
        old_val = self.values.get(name)
        if old_val != value:
            self.values[name] = value
            return True
        else:
            return False
507746
def _call_salt_command(self,
                           fun,
                           args,
                           kwargs,
                           assertion_section=None):
        '''
        
        '''
        value = False
        try:
            if args and kwargs:
                value = self.salt_lc.cmd(fun, *args, **kwargs)
            elif args and not kwargs:
                value = self.salt_lc.cmd(fun, *args)
            elif not args and kwargs:
                value = self.salt_lc.cmd(fun, **kwargs)
            else:
                value = self.salt_lc.cmd(fun)
        except salt.exceptions.SaltException:
            raise
        except Exception:
            raise
        if isinstance(value, dict) and assertion_section:
            return value.get(assertion_section, False)
        else:
            return value
785409
function set(key, value) {
  const entry = this.get(key, true);
  let oldvalue;
  if (entry) {
    oldvalue = entry.value;
    entry.value = value;
  } else {
    oldvalue = this.put(key, value);
    if (oldvalue) oldvalue = oldvalue.value;
  }
  return oldvalue;
}
1209090
def set(self, key, value):
        
        return DatastoreLegacy.store[self.domain].set(key, value)