标签: redis

设置密钥(如果不存在),否则返回其值

我似乎在Redis中找不到找到以下命令的命令:

设置密钥(如果不存在),否则返回其值

有什么方法可以在一次交易中实现这一目标吗?

redis

0
推荐指数
2
解决办法
1242
查看次数

两个应用程序共享一个Redis.如何防止缓存冲突?

两个不同版本的应用程序(调试和发布)共享相同的Redis实例.Debug和Release都具有相同的源代码,因此存储在Redis中的缓存密钥相同.

在此输入图像描述

因此,当Debug redis.StringSet(key1, value1)发布时,Release很容易覆盖key1或读取不正确的值(因为它应该有自己的值key1).

有没有办法避免这种干扰?

redis stackexchange.redis

0
推荐指数
1
解决办法
411
查看次数

redis错误:ERR错误的“ set”命令参数数目

我在本地Redis服务器上的redis set命令有错误(127.0.0.1:6379)

版本:

npm version : 2.15.0;
node version : 4.4.2;
nodejs verison : 0.10.25;
redis version : 2.7.1;
Run Code Online (Sandbox Code Playgroud)

错误:

events.js:141 throw er; // Unhandled 'error' event
ReplyError: ERR wrong number of arguments for 'set' command at parseError 
(/opt/xxx/xxx/node_modules/redis/node_modules/redis 
parser/lib/parser.js:193:12) at parseType 
(/opt/xxx/xxx/node_modules/redis/node_modules/redis-
parser/lib/parser.js:303:14)
Run Code Online (Sandbox Code Playgroud)

我所有的代码如下:

redis.set("key","value")
Run Code Online (Sandbox Code Playgroud)

在我的本地计算机上,代码运行成功,但是在aws linux计算机上,出现此错误。

var matchedMaps = map.get(publicURIField);
            if(matchedMaps) {
                matchedMaps.forEach(function(matchedMap){
                    var patternToValidate = matchedMap.pattern;
                    var type = matchedMap.type;
                    var tagID = matchedMap.tagID;
                    var patternToCheck = "cs-uri-stem";
                    var patternToSave = "";
                    if(type==1){
                        patternToCheck = "c-referrer";
                    } …
Run Code Online (Sandbox Code Playgroud)

backend redis node.js server

0
推荐指数
1
解决办法
6622
查看次数

ERR错误编译脚本(新函数):user_script:2:'='预计在'end'附近,.../lib/site_perl/5.8.7/Redis.pm第163行

我创建了基本的lua脚本,除了一个参数并打印它的值,使用redis-cli执行它没有错误,o/p打印在日志文件中.

$ cat test.lua
 redis.replicate_commands()
 local var = ARGV[1]
 print ( 'var ', var)
$ redis-cli --eval test.lua , A
 nil 
$
Run Code Online (Sandbox Code Playgroud)

我想使用perl脚本运行lua脚本:

$ cat eval.pl
#!/usr/bin/perl

use strict;
use warnings;
use Redis;

my $r = Redis->new(
    server    => '127.0.0.1:6379',
    reconnect => 3,
    every     => 1.5 * 1000000,
    conservative_reconnect => 1,
    no_auto_connect_on_new => 1,
    cnx_timeout            => 15,
);
eval {
    $r->connect;
};
if ($@) {
    print '$@ : '.$@;
}
my $result = $r->eval( "test.lua", 0, 'A' );
print "result …
Run Code Online (Sandbox Code Playgroud)

perl lua redis

0
推荐指数
1
解决办法
975
查看次数

如何在phoenix elixir聊天应用程序中监控树中运行Redix并从不同模块访问

我想在我的聊天应用程序中使用{:redix,"〜> 0.6.1"} hex包,并从监督树开始

{:ok, conn} = Redix.start_link()
{:ok, conn} = Redix.start_link(host: "example.com", port: 5000)
{:ok, conn} = Redix.start_link("redis://localhost:6379/3", name: :redix)


Redix.command(conn, ["SET", "mykey", "foo"])
Run Code Online (Sandbox Code Playgroud)

但是当我尝试将连接开始链接放到子进程时它会出错

children = [
      # Start the Ecto repository
      supervisor(PhoenixChat.Repo, []),
      # Start the endpoint when the application starts
      supervisor(PhoenixChat.Endpoint, []),
      # Start your own worker by calling: PhoenixChat.Worker.start_link(arg1, arg2, arg3)
      # worker(PhoenixChat.Worker, [arg1, arg2, arg3]),
      supervisor(PhoenixChat.Presence, []),

      #supervisor(Phoenix.PubSub.Redis, [:chat_pubsub, host: "127.0.0.1"])
    ]
Run Code Online (Sandbox Code Playgroud)

如何启动redix连接并将数据存储到Redis?

elixir redis elixir-framework phoenix-framework

0
推荐指数
1
解决办法
873
查看次数

使用Redis创建名称为'enableRedisKeyspaceNotificationsInitializer'的bean时出错

我正在尝试使用Redis + MYSQL运行Maven Spring应用程序,但是由于此错误,我无法运行该应用程序,我一直在网上搜索正确的答案,但是找不到。

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-08-08 11:41:31.068 ERROR 8448 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is com.lambdaworks.redis.RedisCommandExecutionException: ERR Unsupported CONFIG parameter: notify-keyspace-events
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at …
Run Code Online (Sandbox Code Playgroud)

java spring maven redis

0
推荐指数
1
解决办法
5860
查看次数

如何将Laravel-Session-Storage设置为Redis?

大家好,我只想将laravel应用程序的会话存储在localhost上的Redis中,redis服务器正在运行,昨天我尝试了Redis :: set('key'),依此类推,它运行良好,但是将会话存储在redis中会导致此错误->未配置Redis连接[redis]。

我的.env文件:

BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
SESSION_DRIVER=redis
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
Run Code Online (Sandbox Code Playgroud)

我的config / session.php文件

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Session Driver
    |--------------------------------------------------------------------------
    |
    | This option controls the default session "driver" that will be used on
    | requests. By default, we will use the lightweight native driver but
    | you may specify any of the other wonderful drivers provided here.
    |
    | Supported: "file", "cookie", "database", "apc",
    |            "memcached", "redis", "array"
    |
    */

    'driver' => env('SESSION_DRIVER', 'redis'),


    /* …
Run Code Online (Sandbox Code Playgroud)

session redis laravel-5

0
推荐指数
1
解决办法
7172
查看次数

Redis Cli中仍显示过期的Redisson密钥

我刚刚也了解了Redis和Redisson。基本上,我试图使用Redis在我的应用程序中存储用于授权的AcessTokens / RefreshTokens。所以我想用到期时间存储令牌。我使用Spring Data Redis来存储令牌,但是没有Api使Map中的每个条目都失效。我碰到了这篇文章Spring Data Redis Expire Key,因此查找了Redisson。我尝试了一个简单的maven java项目来测试到期时间。这是pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.bridgelabz</groupId>
    <artifactId>redissonApp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>redissonApp</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.redisson</groupId>
            <artifactId>redisson</artifactId>
            <version>3.3.0</version>
        </dependency>

    </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

以下是令牌类

package com.bridgelabz.redissonApp;

public class Token {

    private String accessToken;
    private int id;

    public Token() { }


    public Token(String accessToken, int id) {

        this.accessToken = accessToken;
        this.id = id;
    }

    public String getAccessToken() {
        return accessToken;
    } …
Run Code Online (Sandbox Code Playgroud)

redis redisson

0
推荐指数
1
解决办法
1263
查看次数

Redis和MySQL - 什么时候我应该在自己的VS上使用redis什么时候使用它与MySQL一起工作?

我是redis的新手,之前我曾使用MySQL来存储数据.

根据我所学到的知识,我得出结论,两个数据库可能有两种工作模式.一个是redis和MySQL之间的"合作"模式(这有点难以解释所以我绘制了一个图表):

将数据写入数据库

从数据库中读取数据

另一种是仅使用redis'数据库的模式:

只有redis

或者只有MySQL,我以前做过的.

那么,我想知道何时将两种数据库结合起来,何时将它们分开,让它们单独完成工作并执行自己的功能?

如果你能用一个例子说明,我将不胜感激.

mysql database redis

0
推荐指数
1
解决办法
1338
查看次数

Redis在Redis哈希中存储值列表

我的任务是获取特定user_id的动物列表(例如)。

我不想为每个用户使用设置/列表。

我尝试使用哈希,其中每个字段是一个user_id,每个值是一个串联的动物字符串。例如:{"1234" : "dog cat", "8477" : "bird dog"}。在这里,只需调用Redis,即可为用户“ 1234”获取动物。

我知道有一个APPEND命令,可将项目追加到字符串中。但这不适用于将值附加到散列内。

我也尝试过使用set,并通过前缀获取值。对于上面的示例,我的集合将包含:("1234:dog", "1234:cat", "8477:bird", "8477:dog")。为了获取用户“ 1234”的所有动物,我需要搜索前缀“ 1234:”。但是,当我有太多项目时,这不是规模。

我该怎么做才能完成任务?

redis

0
推荐指数
1
解决办法
2355
查看次数