'Internal wrapper for setting values.'

def _set(self, cmd, key, val, flags, expireTime, cas):

    if self._disconnected:
        return fail(RuntimeError('not    connected'))
    if (not isinstance(key, bytes)):
        return fail(ClientError(('Invalid    type    for    key:    %s,    expecting    bytes' % (type(key),))))
    if (len(key) > self.MAX_KEY_LENGTH):
        return fail(ClientError('Key    too    long'))
    if (not isinstance(val, bytes)):
        return fail(ClientError(('Invalid    type    for    value:    %s,    expecting    bytes' % (type(val),))))
    if cas:
        cas = ('    ' + cas)
    length = len(val)
    fullcmd = ('    '.join([cmd, key, networkString(('%d    %d    %d' % (flags, expireTime, length)))]) + cas)
    self.sendLine(fullcmd)
    self.sendLine(val)
    cmdObj = Command(cmd, key=key, flags=flags, length=length)
    self._current.append(cmdObj)
    return cmdObj._deferred
