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,否则返回 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 绑定到 Lua 脚本的 KEYS[n] 特殊数组,values 绑定到 Lua 脚本的 ARGV[n] 特殊数组。 |
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,… 的 map |
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
jars,因为它们已经包含在 neo4j 中)或 apoc 仓库 下载。下载该文件后,应将其放置在 plugins
目录中并重新启动 Neo4j 服务器。
URI 描述
Redis 过程的第一个参数始终是 URI。此 URI 遵循此语法。一个有效的 URI 示例是 redis://myPassword@localhost:6379
配置参数
过程支持以下配置参数
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
charset |
String |
"UTF-8" |
用于编码键和值的字符集 |
timeout |
Long |
60 |
连接超时(秒) |
scriptCharset |
String |
"UTF-8" |
用于编码 Lua 脚本的字符集 |
autoReconnect |
|
true |
启用或禁用连接断开时的自动重连 |
right |
|
true |
用于选择具有“两侧”过程的方向,例如在 |
expireAt |
|
true |
将 MongoDB 数据类型转换为 Neo4j 数据类型 |
codec |
Enum[STRING, BYTE_ARRAY] |
String |
用于编码键和值的 Redis Codec (参见 |
示例
我们来看一些按命令类别划分的示例。
Strings 命令
SET
命令(返回存储的旧值)
CALL apoc.redis.getSet($uri, 'myKey', 'myValue')
value |
---|
null |
或者使用 codec: BYTE_ARRAY
CALL apoc.redis.getSet($uri, `BYTES_KEY`, `BYTES_VALUE`, {codec: "BYTE_ARRAY"})
value |
---|
{"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')
value |
---|
myValue |
APPEND
命令
CALL apoc.redis.append($uri, 'myKey', '2')
value |
---|
myValue2 |
INCRBY
命令,初始值为 '1'
CALL apoc.redis.incrby($uri, 'myKey', 2)
value |
---|
3 |
List 命令
RPUSH
命令
CALL apoc.redis.push($uri, 'myListKey', ['foo','bar','baz'])
value |
---|
3 |
LPUSH
命令
CALL apoc.redis.push($uri, 'myListKey', ['prefix1'], {right: false})
value |
---|
4 |
LRANGE
命令
CALL apoc.redis.lrange($uri, 'myListKey', 0 , 10)
value |
---|
["prefix1", "foo", "bar", "baz"] |
RPOP
命令,使用之前的值
CALL apoc.redis.pop($uri, 'myListKey')
value |
---|
"baz" |
LPOP
命令,使用之前的值
CALL apoc.redis.pop($uri, 'myListKey', {right: false})
value |
---|
"prefix1" |
Sets 命令
SADD
命令
CALL apoc.redis.sadd($uri, 'mySetKey', ['foo','bar','baz'])
value |
---|
3 |
SUNION
命令,结合之前的一个键和另一个包含 ['alpha', 'beta'] 值的键
CALL apoc.redis.sunion($uri, ['mySetKey', 'mySetKeyTwo'])
value |
---|
["foo", "bar", "baz", "alpha", "beta"] |
SCARD
命令,使用之前的键
CALL apoc.redis.scard($uri, 'mySetKey')
value |
---|
3 |
SMEMBERS
命令,使用之前的键
CALL apoc.redis.smembers($uri, 'mySetKey')
value |
---|
["foo", "bar", "baz"] |
SPOP
命令,使用之前的键
CALL apoc.redis.smembers($uri, 'mySetKey')
value |
---|
"baz" |
Sorted sets 命令
ZADD
命令
CALL apoc.redis.zadd($uri, 'mySortedSetKey', [0, 'first', 100, 'third', 1, 'second'])
value |
---|
3 |
ZCARD
命令,使用之前的键
CALL apoc.redis.zcard($uri, 'mySortedSetKey')
value |
---|
3 |
ZRANGEBYSCORE
命令,使用之前的键
CALL apoc.redis.zrangebyscore($uri, 'mySortedSetKey', 0, 100)
value |
---|
["first", "second", "third"] |
ZREM
命令,使用之前的键
CALL apoc.redis.zrem($uri, 'mySortedSetKey', ['first', 'second'])
value |
---|
2 |
Hashes 命令
HSET
命令
CALL apoc.redis.hset($uri, 'mapKey', {alpha: 'beta', gamma: 'delta', epsilon: 'zeta', number: '1'})
value |
---|
4 |
HDEL
命令,使用之前的键
CALL apoc.redis.hdel($uri, 'mapKey', ['alpha', 'gamma'])
value |
---|
2 |
HEXISTS
命令,使用之前的键
CALL apoc.redis.hexists($uri, 'mapKey', 'epsilon')
value |
---|
true |
HGET
命令,使用之前的键
CALL apoc.redis.hget($uri, 'mapKey', 'epsilon')
value |
---|
"zeta" |
HINCRBY
命令,使用之前的键
CALL apoc.redis.hincrby($uri, 'mapKey', 'number', 3)
value |
---|
4 |
Keys 命令
COPY
命令
CALL apoc.redis.copy($uri, 'from', 'to')
value |
---|
true |
EXISTS
命令
CALL apoc.redis.exists($uri, ['to'])
value |
---|
true |
PEXPIRE
命令
CALL apoc.redis.pexpire($uri, 'to', 100, false)
value |
---|
true |
PTTL
命令
CALL apoc.redis.pexpire($uri, 'to')
value |
---|
95 |
PERSIST
命令
CALL apoc.redis.persist($uri, 'to')
value |
---|
true |
Eval 命令
我们可以执行一个 eval 命令,返回值为 BOOLEAN
, INTEGER
, STATUS
, VALUE
或 MULTI
(这些类型之一)。对于值为 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'])
value |
---|
valueEval |