字符串(string)函数

get 命令/方法/函数
Description Get the value related to the specified key 取得与指定的键值相关联的值 Parameters key Return Value String or Bool: If key didn't exist, FALSE is returned. Otherwise, the value related to this key is returned. 返回相关值或者BOOL值,如果KEY不存在,返回FALSE。如果有相关的KEY和值返回值。 Examples $redis->get('key');
set 命令/方法/函数
Description Set the string value in argument as value of the key. 设置值到KEY Parameters Key Value Timeout (optional). Calling SETEX is preferred if you want a timeout. Return value Bool TRUE if the command is successful. Examples $redis->set('key', 'value');
setex 命令/方法/函数
Description Set the string value in argument as value of the key, with a time to live. PSETEX uses a TTL in milliseconds. 设置一个有生命周期的KEY-VALUE,psetex()使用的周期单位为毫秒。 Parameters Key TTL Value Return value Bool TRUE if the command is successful. Examples $redis->setex('key', 3600, 'value'); // sets key → value, with 1h TTL.
psetex 命令/方法/函数
Description Set the string value in argument as value of the key, with a time to live(milliseconds). 设置一个有生命周期的KEY-VALUE,psetex()使用的周期单位为毫秒。 Return value Bool TRUE if the command is successful. Examples $redis->psetex('key', 100, 'value'); // sets key → value, with 0.1 sec TTL.
setnx 命令/方法/函数
Description Set the string value in argument as value of the key if the key doesn't already exist in the database. setnx用于设置一个KEY-VALUE,这个函数会先判断Redis中是否有这个KEY,如果没有就SET,有就返回False。 Parameters key value Return value Bool TRUE in case of success, FALSE in case of failure. Examples $redis->setnx('key', 'value'); /* return TRUE */ $redis->setnx('key', 'value'); /* return FALSE */
delete 命令/方法/函数
Description Remove specified keys. 移除已经存在KEYS Parameters An array of keys, or an undefined number of parameters, each a key: key1 key2 key3 ... keyN 可以是一个KEYS的数组,或者一个未定义的数字参数,或者一个一个的写KEY Return value Long Number of keys deleted. 返回删除KEY-VALUE的数量 Examples $redis->set('key1', 'val1'); $redis->set('key2', 'val2'); $redis->set('key3', 'val3'); $redis->set('key4', 'val4'); $redis->delete('key1', 'key2'); /* return 2 */ $redis->delete(array('key3', 'key4')); /* return 2 */
getSet 命令/方法/函数
Description Sets a value and returns the previous entry at that key. 设置一个VALUE 并且返回该KEY当前的VALUE。 Parameters Key: key STRING: value Return value A string, the previous value located at this key. Example $redis->set('x', '42'); $exValue = $redis->getSet('x', 'lol'); // return '42', replaces x by 'lol' $newValue = $redis->get('x')' // return 'lol'
multi, exec, discard 命令/方法/函数
Description Enter and exit transactional mode. 进入、退出事务处理模式。 Parameters (optional) Redis::MULTI or Redis::PIPELINE. Defaults to Redis::MULTI. A Redis::MULTI block of commands runs as a single transaction; a Redis::PIPELINE block is simply transmitted faster to the server, but without any guarantee of atomicity. discardcancels a transaction. multi函数的参数选项为Redis::MULTI或者是Redis::PIPELINE.默认的是参数是Redis::MULTI。 Redis::MULTI将多个操作当做一个事务来处理。Redis::PIPELINE将作为一个简单快速的处理通道给服务器进行处理,但是不保证处理数据的原子性。 discard()函数取消一个事物处理模式。 Return value multi() returns the Redis instance and enters multi-mode. Once in multi-mode, all subsequent method calls return the same object until exec() is called. multi()返回一个Redis实例,并且这个实例进入到了事务处理模式(批量处理)。当进入到事务处理模式,所有的方法调用都将返回相同的Redis实例,一直到exec()被调用执行事务处理。 Example $ret = $redis->multi() ->set('key1', 'val1') ->get('key1') ->set('key2', 'val2') ->get('key2') ->exec(); /* $ret == array( 0 => TRUE, 1 => 'val1', 2 => TRUE, 3 => 'val2'); */
watch 命令/方法/函数
Description Watches a key for modifications by another client. If the key is modified between WATCH and EXEC, the MULTI/EXEC transaction will fail (return FALSE). 监控一个KEY是否被其他的客户端修改。如果KEY在调用watch()和exec()之间被修改,那么批量处理最终的exec()执行将失败。通过一些实验,这个函数的效果其实并没有那么好,或者说不能够准确的去监控。 Parameters keys: a list of keys Example $redis->watch('x'); /* long code here during the execution of which other clients could well modify `x` */ $ret = $redis->multi() ->incr('x') ->exec(); /* $ret = FALSE if x has been modified between the call to WATCH and the call to EXEC. */
unwatch 命令/方法/函数
Description unwatch cancels all the watching of all keys by this client. unwatch()取消对于所有KEY值的监控操作针对于这个Redis实例。通过一些实验,这个函数的效果其实并没有那么好,或者说不能够准确的去监控。
subscribe 命令/方法/函数
Description Subscribe to channels. Warning: this function will probably change in the future. 方法回调函数,注意:该方法在将来有可能被修改。 Parameters channels: an array of channels to subscribe to callback: either a string or an array($instance, 'method_name'). The callback function receives 3 parameters: the redis instance, the channel name, and the message. Example function f($redis, $chan, $msg) { switch($chan) { case 'chan-1': ... break; case 'chan-2': ... break; case 'chan-2': ... break; } } $redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
publish 命令/方法/函数
Description Publish messages to channels. Warning: this function will probably change in the future. 将消息发布到信道。警告:这个功能可能会在未来发生变化。 Parameters channel: a channel to publish to messsage: string Example $redis->publish('chan-1', 'hello, world!'); // send message.
exists 命令/方法/函数
Description Verify if the specified key exists. 验证一个指定的KEY是否存在。 Parameters key Return value BOOL: If the key exists, return TRUE, otherwise return FALSE. BOOL:如果key存在,返回true,否则返回false。 Examples $redis->set('key', 'value'); $redis->exists('key'); /* TRUE */ $redis->exists('NonExistingKey'); /* FALSE */
incr 命令/方法/函数
Description Increment the number stored at key by one. If the second argument is filled, it will be used as the integer value of the increment. 对指定的KEY的值自增1。如何填写了第二个参数,将把第二个参数自增给KEY的值。 Parameters key value: value that will be added to key (only for incrBy) Return value INT the new value 返回新的INT数值 Examples $redis->incr('key1'); /* key1 didn't exists, set to 0 before the increment 如果key1不存在,在自增之前的默认值为0 */ /* and now has the value 1 执行incr后,现在为1 */ $redis->incr('key1'); /* 2 */ $redis->incr('key1'); /* 3 */
incrBy 命令/方法/函数
Description 对key的值加num,比如 incrby("ab", 10),相当于:ab+10 Return value INT the new value 返回新的INT数值 Examples $redis->incrBy('key1', 10); /* 如果key1的值为8,那么结果为:18 */
incrByFloat 命令/方法/函数
Increment the key with floating point precision. 自增一个浮点型的数值。 Parameters key value: (float) value that will be added to the key Return value FLOAT the new value Examples $redis->incrByFloat('key1', 1.5); /* key1 didn't exist, so it will now be 1.5 */ $redis->incrByFloat('key1', 1.5); /* 3 */ $redis->incrByFloat('key1', -1.5); /* 1.5 */ $redis->incrByFloat('key1', 2.5); /* 3.5 */
decr 命令/方法/函数
对指定的KEY的值自减1(如果要自减指定的值,可以使用decrBy) Parameters key value: value that will be substracted to key (only for decrBy) Return value INT the new value Examples $redis->decr('key1'); /* key1 didn't exists, set to 0 before the increment */ /* and now has the value -1 */ $redis->decr('key1'); /* -2 */ $redis->decr('key1'); /* -3 */
decrBy 命令/方法/函数
减去指定的值。 Return value INT the new value Examples $redis->set('key1', 50); $redis->decrBy('key1', 10); /* result:40 */
mGet 命令/方法/函数
Description Get the values of all the specified keys. If one or more keys dont exist, the array will contain FALSE at the position of the key. 取得所有指定KEYS的值,如果一个或者更多的KEYS不存在,那么返回的ARRAY中将在相应的KEYS的位置填充FALSE。 Parameters Array: Array containing the list of the keys 数组:一个KEYS的数组 Return value Array: Array containing the values related to keys in argument 数组:返回相应的KEYS的值 Examples $redis->set('key1', 'value1'); $redis->set('key2', 'value2'); $redis->set('key3', 'value3'); $redis->mGet(array('key1', 'key2', 'key3')); /* array('value1', 'value2', 'value3'); $redis->mGet(array('key0', 'key1', 'key5')); /* array(`FALSE`, 'value2', `FALSE`);
append 命令/方法/函数
Description Append specified string to the string stored in specified key. 添加指定的字符串到指定的字符串KEY。 Parameters Key Value Return value INTEGER: Size of the value after the append 返回添加后KEY的SIZE Example $redis->set('key', 'value1'); $redis->append('key', 'value2'); /* 12 */ $redis->get('key'); /* 'value1value2' */
getRange 命令/方法/函数
getRange(substr also supported but deprecated in redis) Description Return a substring of a larger string 返回字符串的一部分 Parameters key start end Return value STRING: the substring Example $redis->set('key', 'string value'); $redis->getRange('key', 0, 5); /* 'string' */ $redis->getRange('key', -5, -1); /* 'value' */
setRange 命令/方法/函数
Description Changes a substring of a larger string. 修改字符串的一部分。 Parameters key offset value Return value STRING: the length of the string after it was modified. Example $redis->set('key', 'Hello world'); $redis->setRange('key', 6, "redis"); /* returns 11 */ $redis->get('key'); /* "Hello redis" */
strlen 命令/方法/函数
Description Get the length of a string value. 返回字符串的长度。 Parameters key Return value INTEGER Example $redis->set('key', 'value'); $redis->strlen('key'); /* 5 */
getBit 命令/方法/函数
Description Return a single bit out of a larger string 将一个位返回一个较大的字符串 Parameters key offset Return value LONG: the bit value (0 or 1) Example $redis->set('key', "\x7f"); // this is 0111 1111 $redis->getBit('key', 0); /* 0 */ $redis->getBit('key', 1); /* 1 */
setBit 命令/方法/函数
Description Changes a single bit of a string. Parameters key offset value: bool or int (1 or 0) Return value LONG: 0 or 1, the value of the bit before it was set. Example $redis->set('key', "*"); // ord("*") = 42 = 0x2f = "0010 1010" $redis->setBit('key', 5, 1); /* returns 0 */ $redis->setBit('key', 7, 1); /* returns 0 */ $redis->get('key'); /* chr(0x2f) = "/" = b("0010 1111") */
bitop 命令/方法/函数
Description Bitwise operation on multiple keys.
对一个或多个保存二进制位的字符串 key 进行位元操作,并将结果保存到 destkey 上。 Parameters operation: either "AND", "OR", "NOT", "XOR" ret_key: return key key1 key2... Return value LONG: The size of the string stored in the destination key.
bitcount 命令/方法/函数
Description Count bits in a string. Parameters key Return value LONG: The number of bits set to 1 in the value behind the input key. example
https://blog.csdn.net/ma_jiang/article/details/61421888
mset 命令/方法/函数
Description Sets multiple key-value pairs in one atomic command. MSETNX only returns TRUE if all the keys were set (see SETNX). 批量设置多个KEY-VALUE。如果所有的KEYS都被设置成功,如果这些KEY-VALUE都SET成功,使用msetnx将仅仅返回一个TURE,而如果有一个是已经存在的KEY,则所有的操作都不被执行。 Parameters Pairs: array(key => value, ...) Return value Bool TRUE in case of success, FALSE in case of failure. Example $redis->mset(array('key0' => 'value0', 'key1' => 'value1')); var_dump($redis->get('key0')); var_dump($redis->get('key1')); Output: string(6) "value0" string(6) "value1"

redis 字符串(string)函数的更多相关文章

  1. Python操作redis字符串(String)详解 (三)

    # -*- coding: utf-8 -*- import redis #这个redis不能用,请根据自己的需要修改 r =redis.Redis(host=") 1.SET 命令用于设置 ...

  2. Redis字符串(STRING)中BIT相关命令

    上篇文章我们对STRING数据类型中一些基本的命令进行了介绍,但是没有涉及到BIT相关的命令,本文我们就来看看几个和BIT相关的命令. 本文是Redis系列的第四篇文章,了解前面的文章有助于更好的理解 ...

  3. Redis 字符串(String)

      Redis 字符串数据类型的相关命令用于管理 redis 字符串值,基本语法如下: 语法 redis 127.0.0.1:6379> COMMAND KEY_NAME 实例 redis 12 ...

  4. redis(六):Redis 字符串(String)

    Redis 字符串数据类型的相关命令用于管理 redis 字符串值,基本语法如下: 语法 redis 127.0.0.1:6379> COMMAND KEY_NAME 实例 redis 127. ...

  5. redis -字符串string

    字符串类型是Redis 中最为基础的数据存储类型,它在Redis 中是二进制安全的,该类型可以接收任何格式的数据,  字符串 Value 最多可以容纳的数据长度是521M. 保存: 设置键值. set ...

  6. (二)Redis字符串String操作

    String全部命令如下: set key value # 设置一个key的value值 get key # 获取key的value值 mset key1 value1 key2 value2 ... ...

  7. redis(七):Redis 字符串(String)(python)

    # -*- coding: utf-8 -*- import redis #这个redis不能用,请根据自己的需要修改 r =redis.Redis(host="123.516.74.190 ...

  8. C#字符串string以及相关内置函数

    C#字符串string函数 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享. ...

  9. Redis 命令,键(key),字符串(String),哈希(Hash),列表(List),集合(Set)(二)

      Redis 命令 Redis 命令用于在 redis 服务上执行操作. 要在 redis 服务上执行命令需要一个 redis 客户端.Redis 客户端在我们之前下载的的 redis 的安装包中. ...

随机推荐

  1. NOIP2009 t3 最优贸易

    题目传送门:洛谷P1073 dalao们都用的tarjan啊拓扑排序啊之类的玩意儿,我这个蒟蒻不会,只想到了极其暴力的分层图最短路 设三个状态 0表示没有发生任何买卖的情况 1表示买了没有卖的情况 2 ...

  2. Ackerman

    Ackerman 递归算法 一 . 问题描述及分析 图1 二 . 代码实现 package other; import java.io.BufferedWriter; import java.io.F ...

  3. 执行Android后台任务的最佳实践

    灵活执行后台任务可以帮助提升应用性能,并最小化电量损耗. Android后台任务主题包含以下三个子主题: 1. 在IntentService中执行后台任务: 2. 使用CursorLoader在后台加 ...

  4. centos如何设置固定IP

    ### centos6.5版本 编辑ifcfg-eth0 vi /etc/sysconfig/network-scripts/ifcfg-eth0 参照下面代码修改自己的配置 ############ ...

  5. python学习:缩进

    缩进 一要求: 官方建议打四个空格.tab键不建议使用,放到其他操作系统容易出现混乱.(打四个空格太费劲) 二实现: 简便方法:每按一下tab键自动换成四个空格.notepad++ 设置里首选项-制表 ...

  6. yield学习笔记

    参考:http://www.dabeaz.com/finalgenerator/ from concurrent.futures import ThreadPoolExecutor import ti ...

  7. [LeetCode] Generate Random Point in a Circle 生成圆中的随机点

    Given the radius and x-y positions of the center of a circle, write a function randPoint which gener ...

  8. CodeForces #549 Div.2 D. The Beatles

    题目 解题思路 关键是要 ,找出L 的组合,然后遍历L的组合,用最大公约数就可以算出来当前L的值要停多少次 怎么找出L的组合呢?饭店是每隔K 有一个,是重复的,我们只需要算出第一个饭店两侧,起点和停顿 ...

  9. python 去掉重复元素 学到再添加

    1. python 内置函数 set(可迭代对象) 返回无重复元素的集合.如在分类中,classification为类别数组 set(classification)为类别数 2.numpy np.un ...

  10. mysql自动更新时间

    ALTER TABLE sys_user MODIFY COLUMN update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDAT ...