Redis
以下是所有可用的 Redis 过程的列表
名称 | 签名 | 描述 |
---|---|---|
apoc.redis.append |
apoc.redis.append(uri :: STRING?, key :: STRING?, value :: STRING?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.append(uri, key, value, {config}) | 执行 'APPEND key value' 命令 |
apoc.redis.configGet |
apoc.redis.configGet(uri :: STRING?, parameter :: STRING?, config = {} :: MAP?) :: (value :: MAP?) |
apoc.redis.configGet(uri, parameter, {config}) | 执行 'CONFIG GET parameter' 命令 |
apoc.redis.configSet |
apoc.redis.configSet(uri :: STRING?, parameter :: STRING?, value :: STRING?, config = {} :: MAP?) :: (value :: STRING?) |
apoc.redis.configSet(uri, parameter, {config}) | 执行 'CONFIG SET parameter value' 命令 |
apoc.redis.copy |
apoc.redis.copy(uri :: STRING?, source :: STRING?, destination :: STRING?, config = {} :: MAP?) :: (value :: BOOLEAN?) |
apoc.redis.copy(uri, source, destination, {config}) | 执行 'COPY source destination' 命令并返回 true 如果 source 被复制,否则返回 false |
apoc.redis.eval |
apoc.redis.eval(uri :: STRING?, script :: STRING?, outputType :: STRING?, keys :: LIST? OF STRING?, values :: LIST? OF STRING?, config = {} :: MAP?) :: (value :: ANY?) |
apoc.redis.eval(uri, script, outputType, keys, values, {config}) | 执行 'EVAL script' 命令。在提供给该过程的参数中,键绑定到 KEYS[n] 类似于 Lua 脚本的特殊数组,值绑定到 ARGV[n] 类似于 Lua 脚本的特殊数组。 |
apoc.redis.exists |
apoc.redis.exists(uri :: STRING?, keys :: LIST? OF STRING?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.exists(uri, keys, {config}) | 执行 'EXISTS keys' 命令 |
apoc.redis.get |
apoc.redis.get(uri :: STRING?, key :: STRING?, config = {} :: MAP?) :: (value :: STRING?) |
apoc.redis.get(uri, key, {config}) | 执行 'GET key' 命令 |
apoc.redis.hdel |
apoc.redis.hdel(uri :: STRING?, key :: STRING?, fields :: LIST? OF STRING?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.hdel(uri, key, fields, {config}) | 执行 'HDEL key fields' 命令 |
apoc.redis.hexists |
apoc.redis.hexists(uri :: STRING?, key :: STRING?, field :: STRING?, config = {} :: MAP?) :: (value :: BOOLEAN?) |
apoc.redis.hexists(uri, key, field, {config}) | 执行 'HEXISTS key field' 命令 |
apoc.redis.hget |
apoc.redis.hget(uri :: STRING?, key :: STRING?, field :: STRING?, config = {} :: MAP?) :: (value :: STRING?) |
apoc.redis.hget(uri, key, field, {config}) | 执行 'HGET key field' 命令 |
apoc.redis.hgetall |
apoc.redis.hgetall(uri :: STRING?, key :: STRING?, config = {} :: MAP?) :: (value :: MAP?) |
apoc.redis.hgetall(uri, key, {config}) | 执行 'HGETALL key' 命令 |
apoc.redis.hincrby |
apoc.redis.hincrby(uri :: STRING?, key :: STRING?, field :: STRING?, amount :: INTEGER?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.hincrby(uri, key, field, amount, {config}) | 执行 'HINCRBY key field amount' 命令 |
apoc.redis.hset |
apoc.redis.hset(uri :: STRING?, key :: STRING?, field :: MAP?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.hset(uri, key, value, {config}) | 执行 'HSET key mapFields' 命令,其中 mapFields 是一个 field1, value1, field2, value2,… 的映射。 |
apoc.redis.incrby |
apoc.redis.incrby(uri :: STRING?, key :: STRING?, amount :: INTEGER?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.incrby(uri, key, amount, {config}) | 执行 'INCRBY key increment' 命令 |
apoc.redis.info |
apoc.redis.info(uri :: STRING?, config = {} :: MAP?) :: (value :: STRING?) |
apoc.redis.info(uri, {config}) | 执行 'INFO' 命令 |
apoc.redis.lrange |
apoc.redis.lrange(uri :: STRING?, key :: STRING?, start :: INTEGER?, stop :: INTEGER?, config = {} :: MAP?) :: (value :: LIST? OF ANY?) |
apoc.redis.lrange(uri, key, start, stop, {config}) | 执行 'LRANGE key start stop' 命令 |
apoc.redis.persist |
apoc.redis.persist(uri :: STRING?, key :: STRING?, config = {} :: MAP?) :: (value :: BOOLEAN?) |
apoc.redis.persist(uri, key, {config}) | 执行 'PERSIST key' 命令 |
apoc.redis.pexpire |
apoc.redis.pexpire(uri :: STRING?, key :: STRING?, time :: INTEGER?, config = {} :: MAP?) :: (value :: BOOLEAN?) |
apoc.redis.pexpire(uri, key, time, isExpireAt {config}) | 执行 'PEXPIRE key time' 命令,如果 isExpireAt=true,则执行 'PEPXPIREAT' 命令 |
apoc.redis.pop |
apoc.redis.pop(uri :: STRING?, key :: STRING?, config = {} :: MAP?) :: (value :: STRING?) |
apoc.redis.pop(uri, key, {config}) | 执行 'LPOP key' 命令,如果 config right=true (默认)则执行 'RPOP' 命令 |
apoc.redis.pttl |
apoc.redis.pttl(uri :: STRING?, key :: STRING?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.pttl(uri, key, {config}) | 执行 'PTTL key' 命令 |
apoc.redis.push |
apoc.redis.push(uri :: STRING?, key :: STRING?, value :: LIST? OF STRING?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.push(uri, key, values, {config}) | 执行 'LPUSH key field values' 命令,如果 config right=true (默认)则执行 'RPUSH' 命令 |
apoc.redis.sadd |
apoc.redis.sadd(uri :: STRING?, key :: STRING?, members :: LIST? OF STRING?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.sadd(uri, key, members, {config}) | 执行 'SADD key members' 命令 |
apoc.redis.scard |
apoc.redis.scard(uri :: STRING?, key :: STRING?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.scard(uri, key, {config}) | 执行 'SCARD key' 命令 |
apoc.redis.getSet |
apoc.redis.getSet(uri :: STRING?, key :: STRING?, value :: STRING?, config = {} :: MAP?) :: (value :: STRING?) |
apoc.redis.getSet(uri, key, value, {config}) | 执行 'SET key value' 命令并返回旧值(如果不存在则为 null) |
apoc.redis.smembers |
apoc.redis.smembers(uri :: STRING?, key :: STRING?, config = {} :: MAP?) :: (value :: LIST? OF ANY?) |
apoc.redis.smembers(uri, key, {config}) | 执行 'SMEMBERS key' 命令 |
apoc.redis.spop |
apoc.redis.spop(uri :: STRING?, key :: STRING?, config = {} :: MAP?) :: (value :: STRING?) |
apoc.redis.spop(uri, key, {config}) | 执行 'SPOP key' 命令 |
apoc.redis.sunion |
apoc.redis.sunion(uri :: STRING?, keys :: LIST? OF STRING?, config = {} :: MAP?) :: (value :: LIST? OF ANY?) |
apoc.redis.sunion(uri, keys, {config}) | 执行 'SUNION keys' 命令 |
apoc.redis.zadd |
apoc.redis.zadd(uri :: STRING?, key :: STRING?, value :: LIST? OF ANY?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.zadd(uri, keys, scoresAndMembers, {config}) | 执行 'ZADD key scoresAndMembers' 命令,其中 scoresAndMembers 是一个 score,member,score,member,… 的列表。 |
apoc.redis.zcard |
apoc.redis.zcard(uri :: STRING?, key :: STRING?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.zcard(uri, key, {config}) | 执行 'ZCARD key' 命令 |
apoc.redis.zrangebyscore |
apoc.redis.zrangebyscore(uri :: STRING?, key :: STRING?, min :: INTEGER?, max :: INTEGER?, config = {} :: MAP?) :: (value :: LIST? OF ANY?) |
apoc.redis.zrangebyscore(uri, key, min, max, {config}) | 执行 'ZRANGEBYSCORE key min max' 命令 |
apoc.redis.zrem |
apoc.redis.zrem(uri :: STRING?, key :: STRING?, members :: LIST? OF STRING?, config = {} :: MAP?) :: (value :: INTEGER?) |
apoc.redis.zrem(uri, key, members, {config}) | 执行 'ZREM key members' 命令 |
安装依赖项
Redis 过程依赖于 APOC 扩展库中未包含的客户端库。您可以从 lettuce-core 存储库(除了 netty
jar 包,因为它们已经包含在 neo4j 中)或 apoc 存储库 下载该文件。下载该文件后,应将其放置在 plugins
目录中,然后重新启动 Neo4j 服务器。
URI 描述
Redis 过程的第一个参数始终是 URI。此 URI 遵循 此语法。有效 uri 的一个示例是 redis://myPassword@localhost:6379
配置参数
这些过程支持以下配置参数
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
字符集 |
字符串 |
"UTF-8" |
用于编码键和值的字符集 |
超时 |
长整数 |
60 |
连接超时(以秒为单位) |
scriptCharset |
字符串 |
"UTF-8" |
用于编码脚本的 Lua 脚本字符集 |
自动重新连接 |
|
true |
启用或禁用连接丢失时的自动重新连接 |
right |
|
true |
选择具有“两面”的程序的方向情况,例如在 |
expireAt |
|
true |
将 MongoDB 数据类型转换为 Neo4j 数据类型 |
编解码器 |
枚举[STRING, BYTE_ARRAY] |
字符串 |
用于编码键和值的 Redis 编解码器(请参阅 |
示例
让我们看一些按命令类别划分的示例。
Strings commands
SET
命令(返回存储的旧值)
CALL apoc.redis.getSet($uri, 'myKey', 'myValue')
值 |
---|
null |
或者使用编解码器:BYTE_ARRAY
CALL apoc.redis.getSet($uri, `BYTES_KEY`, `BYTES_VALUE`, {codec: "BYTE_ARRAY"})
值 |
---|
{"0":31.0,"1":-117.0,"2":8.0,"3":0.0,"4":0.0,"5":0.0,"6":0.0,"7":0.0,"8":0.0,"9":-1.0,"10":75.0,"11":4.0,"12":0.0,"13":67.0,"14":-66.0,"15":-73.0,"16":-24.0,"17":1.0,"18":0.0,"19":0.0,"20":0.0} |
GET
命令
CALL apoc.redis.get($uri, 'myKey')
值 |
---|
myValue |
APPEND
命令
CALL apoc.redis.append($uri, 'myKey', '2')
值 |
---|
myValue2 |
INCRBY
命令,初始值为 '1''
CALL apoc.redis.incrby($uri, 'myKey', 2)
值 |
---|
3 |
List commands
RPUSH
命令
CALL apoc.redis.push($uri, 'myListKey', ['foo','bar','baz'])
值 |
---|
3 |
LPUSH
命令
CALL apoc.redis.push($uri, 'myListKey', ['prefix1'], {right: false})
值 |
---|
4 |
LRANGE
命令
CALL apoc.redis.lrange($uri, 'myListKey', 0 , 10)
值 |
---|
["prefix1", "foo", "bar", "baz"] |
RPOP
命令,具有先前的值
CALL apoc.redis.pop($uri, 'myListKey')
值 |
---|
"baz" |
LPOP
命令,具有先前的值
CALL apoc.redis.pop($uri, 'myListKey', {right: false})
值 |
---|
"prefix1" |
Sets commands
SADD
命令
CALL apoc.redis.sadd($uri, 'mySetKey', ['foo','bar','baz'])
值 |
---|
3 |
SUNION
命令,具有先前的值和第二个键,其值为 ['alpha', 'beta']
CALL apoc.redis.sunion($uri, ['mySetKey', 'mySetKeyTwo'])
值 |
---|
["foo", "bar", "baz", "alpha", "beta"] |
SCARD
命令,具有先前的键
CALL apoc.redis.scard($uri, 'mySetKey')
值 |
---|
3 |
SMEMBERS
命令,具有先前的键
CALL apoc.redis.smembers($uri, 'mySetKey')
值 |
---|
["foo", "bar", "baz"] |
SPOP
命令,具有先前的键
CALL apoc.redis.smembers($uri, 'mySetKey')
值 |
---|
"baz" |
Sorted sets commands
ZADD
命令
CALL apoc.redis.zadd($uri, 'mySortedSetKey', [0, 'first', 100, 'third', 1, 'second'])
值 |
---|
3 |
ZCARD
命令,具有先前的键
CALL apoc.redis.zcard($uri, 'mySortedSetKey')
值 |
---|
3 |
ZRANGEBYSCORE
命令,具有先前的键
CALL apoc.redis.zrangebyscore($uri, 'mySortedSetKey', 0, 100)
值 |
---|
["first", "second", "third"] |
ZREM
命令,具有先前的键
CALL apoc.redis.zrem($uri, 'mySortedSetKey', ['first', 'second'])
值 |
---|
2 |
Hashes commands
HSET
命令
CALL apoc.redis.hset($uri, 'mapKey', {alpha: 'beta', gamma: 'delta', epsilon: 'zeta', number: '1'})
值 |
---|
4 |
HDEL
命令,具有先前的键
CALL apoc.redis.hdel($uri, 'mapKey', ['alpha', 'gamma'])
值 |
---|
2 |
HEXISTS
命令,具有先前的键
CALL apoc.redis.hexists($uri, 'mapKey', 'epsilon')
值 |
---|
true |
HGET
命令,具有先前的键
CALL apoc.redis.hget($uri, 'mapKey', 'epsilon')
值 |
---|
"zeta" |
HINCRBY
命令,具有先前的键
CALL apoc.redis.hincrby($uri, 'mapKey', 'number', 3)
值 |
---|
4 |
Keys commands
COPY
命令
CALL apoc.redis.copy($uri, 'from', 'to')
值 |
---|
true |
EXISTS
命令
CALL apoc.redis.exists($uri, ['to'])
值 |
---|
true |
PEXPIRE
命令
CALL apoc.redis.pexpire($uri, 'to', 100, false)
值 |
---|
true |
PTTL
命令
CALL apoc.redis.pexpire($uri, 'to')
值 |
---|
95 |
PERSIST
命令
CALL apoc.redis.persist($uri, 'to')
值 |
---|
true |
Eval command
我们可以使用返回值 BOOLEAN
、INTEGER
、STATUS
、VALUE
或 MULTI
(这些类型)执行 eval 命令。使用具有值 valueEval
的 keyEval
,我们可以执行 EVAL return redis.call("get", KEYS[1]) testEval 'key:name'
命令,并返回 'VALUE'。
CALL apoc.redis.eval($uri, 'return redis.call("get", KEYS[1])', 'VALUE', ['testEval'], ['key:name'])
值 |
---|
valueEval |