Redis values set from Python are not reflecting in redis client












0















I have installed redis on my OS X, and trying to set and get some values in Redis from Python 3.5 client. I have the Redis server on (through command redis-server) and the redis-client on as well (opened through the command redis-cli). This is what I am trying on Python:



import redis
r = redis.StrictRedis()
r.set("foo", "bar")
r.get("foo")


This prints bar as expected. However, if I go to my redis-client prompt and try get foo, it returns nil. In the same way, if I set a value in the redis-client itself, like set boo too, calling get boo in the client returns too as expected, however, in my Python client if I run r.get(boo), I get None.



Funny thing is, they are synced between their own instances. So if I open another Python command prompt and type r.get("foo"), it returns bar. In the same way, if I open another redis-cli instance and type get boo, I get too. It is only that the values between Python client and Redis client are not syncing. I even tried to enforce a bgsave from Python client after setting the value there, and it did trigger a save in the window where redis-server is running, but the values do not reflect in the redis-cli window even after that.



They were working perfectly fine until some days back, this has started happening sometime recently.



Any idea how to fix this?










share|improve this question























  • You are obviously not connecting to the same redis-server from the clis and python code...

    – Itamar Haber
    Nov 21 '18 at 16:44











  • I guessed as much, but cannot understand how to connect both to the same instance, and why did this start to happen suddenly!

    – SexyBeast
    Nov 21 '18 at 17:34
















0















I have installed redis on my OS X, and trying to set and get some values in Redis from Python 3.5 client. I have the Redis server on (through command redis-server) and the redis-client on as well (opened through the command redis-cli). This is what I am trying on Python:



import redis
r = redis.StrictRedis()
r.set("foo", "bar")
r.get("foo")


This prints bar as expected. However, if I go to my redis-client prompt and try get foo, it returns nil. In the same way, if I set a value in the redis-client itself, like set boo too, calling get boo in the client returns too as expected, however, in my Python client if I run r.get(boo), I get None.



Funny thing is, they are synced between their own instances. So if I open another Python command prompt and type r.get("foo"), it returns bar. In the same way, if I open another redis-cli instance and type get boo, I get too. It is only that the values between Python client and Redis client are not syncing. I even tried to enforce a bgsave from Python client after setting the value there, and it did trigger a save in the window where redis-server is running, but the values do not reflect in the redis-cli window even after that.



They were working perfectly fine until some days back, this has started happening sometime recently.



Any idea how to fix this?










share|improve this question























  • You are obviously not connecting to the same redis-server from the clis and python code...

    – Itamar Haber
    Nov 21 '18 at 16:44











  • I guessed as much, but cannot understand how to connect both to the same instance, and why did this start to happen suddenly!

    – SexyBeast
    Nov 21 '18 at 17:34














0












0








0








I have installed redis on my OS X, and trying to set and get some values in Redis from Python 3.5 client. I have the Redis server on (through command redis-server) and the redis-client on as well (opened through the command redis-cli). This is what I am trying on Python:



import redis
r = redis.StrictRedis()
r.set("foo", "bar")
r.get("foo")


This prints bar as expected. However, if I go to my redis-client prompt and try get foo, it returns nil. In the same way, if I set a value in the redis-client itself, like set boo too, calling get boo in the client returns too as expected, however, in my Python client if I run r.get(boo), I get None.



Funny thing is, they are synced between their own instances. So if I open another Python command prompt and type r.get("foo"), it returns bar. In the same way, if I open another redis-cli instance and type get boo, I get too. It is only that the values between Python client and Redis client are not syncing. I even tried to enforce a bgsave from Python client after setting the value there, and it did trigger a save in the window where redis-server is running, but the values do not reflect in the redis-cli window even after that.



They were working perfectly fine until some days back, this has started happening sometime recently.



Any idea how to fix this?










share|improve this question














I have installed redis on my OS X, and trying to set and get some values in Redis from Python 3.5 client. I have the Redis server on (through command redis-server) and the redis-client on as well (opened through the command redis-cli). This is what I am trying on Python:



import redis
r = redis.StrictRedis()
r.set("foo", "bar")
r.get("foo")


This prints bar as expected. However, if I go to my redis-client prompt and try get foo, it returns nil. In the same way, if I set a value in the redis-client itself, like set boo too, calling get boo in the client returns too as expected, however, in my Python client if I run r.get(boo), I get None.



Funny thing is, they are synced between their own instances. So if I open another Python command prompt and type r.get("foo"), it returns bar. In the same way, if I open another redis-cli instance and type get boo, I get too. It is only that the values between Python client and Redis client are not syncing. I even tried to enforce a bgsave from Python client after setting the value there, and it did trigger a save in the window where redis-server is running, but the values do not reflect in the redis-cli window even after that.



They were working perfectly fine until some days back, this has started happening sometime recently.



Any idea how to fix this?







python python-3.x redis redis-server






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 16:09









SexyBeastSexyBeast

2,5351974151




2,5351974151













  • You are obviously not connecting to the same redis-server from the clis and python code...

    – Itamar Haber
    Nov 21 '18 at 16:44











  • I guessed as much, but cannot understand how to connect both to the same instance, and why did this start to happen suddenly!

    – SexyBeast
    Nov 21 '18 at 17:34



















  • You are obviously not connecting to the same redis-server from the clis and python code...

    – Itamar Haber
    Nov 21 '18 at 16:44











  • I guessed as much, but cannot understand how to connect both to the same instance, and why did this start to happen suddenly!

    – SexyBeast
    Nov 21 '18 at 17:34

















You are obviously not connecting to the same redis-server from the clis and python code...

– Itamar Haber
Nov 21 '18 at 16:44





You are obviously not connecting to the same redis-server from the clis and python code...

– Itamar Haber
Nov 21 '18 at 16:44













I guessed as much, but cannot understand how to connect both to the same instance, and why did this start to happen suddenly!

– SexyBeast
Nov 21 '18 at 17:34





I guessed as much, but cannot understand how to connect both to the same instance, and why did this start to happen suddenly!

– SexyBeast
Nov 21 '18 at 17:34












1 Answer
1






active

oldest

votes


















0














It seems to me that you are accessing (setting/getting values) through different dbs in your redis-cli and your redis-py instance. redis servers can have multiple key-value stores (or "tables") completely isolated from one another. These are referred throughout the documentation as db, and are uniquely identified by integers.



If you are instancing redis-py exactly as in your code snippet, with:



import redis
r = redis.StrictRedis()


Then you are using the constructor's default value for db, which is 0. (See documentation)



If the values differ between the Python implementation and redis-cli, then most likely your command line client is running on a different dbthan 0. You can check which db you are working on with the command CLIENT LIST, which will return your current database id.



To switch to the same database as the Python implementation, just run on your redis-cli:



SELECT 0


(See documentation)



Or, alternatively, you can call your redis-py constructor with the desired db parameter:



r = redis.StrictRedis(db=3) # 3 is an example value for your redis-cli's working db





share|improve this answer
























  • Thanks. I instantiated it with db value as 3 in Python, and set it to so in Redis as well: SELECT 3. Output: 127.0.0.1:6379[3]> get foo (nil)

    – SexyBeast
    Nov 21 '18 at 17:37













  • @SexyBeast your redis-py database value was definitely set to 0, whereas you don't know which database your redis-cli was using, so you can't expect to be able to get the same value with 100% certainty. Try running SELECT 0 and then GET foo in your redis-cli

    – felipecgonc
    Nov 21 '18 at 18:17











  • That's what I said, I tried setting it to 3 in both, then ran the commands. Still not reflecting..

    – SexyBeast
    Nov 21 '18 at 18:20











  • @SexyBeast but did you also run SET foo bar (in any one of the clients) after setting both databases to 3?

    – felipecgonc
    Nov 21 '18 at 18:24











  • Yes. Did that. And still not reflecting! :(

    – SexyBeast
    Nov 21 '18 at 18:26











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416131%2fredis-values-set-from-python-are-not-reflecting-in-redis-client%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














It seems to me that you are accessing (setting/getting values) through different dbs in your redis-cli and your redis-py instance. redis servers can have multiple key-value stores (or "tables") completely isolated from one another. These are referred throughout the documentation as db, and are uniquely identified by integers.



If you are instancing redis-py exactly as in your code snippet, with:



import redis
r = redis.StrictRedis()


Then you are using the constructor's default value for db, which is 0. (See documentation)



If the values differ between the Python implementation and redis-cli, then most likely your command line client is running on a different dbthan 0. You can check which db you are working on with the command CLIENT LIST, which will return your current database id.



To switch to the same database as the Python implementation, just run on your redis-cli:



SELECT 0


(See documentation)



Or, alternatively, you can call your redis-py constructor with the desired db parameter:



r = redis.StrictRedis(db=3) # 3 is an example value for your redis-cli's working db





share|improve this answer
























  • Thanks. I instantiated it with db value as 3 in Python, and set it to so in Redis as well: SELECT 3. Output: 127.0.0.1:6379[3]> get foo (nil)

    – SexyBeast
    Nov 21 '18 at 17:37













  • @SexyBeast your redis-py database value was definitely set to 0, whereas you don't know which database your redis-cli was using, so you can't expect to be able to get the same value with 100% certainty. Try running SELECT 0 and then GET foo in your redis-cli

    – felipecgonc
    Nov 21 '18 at 18:17











  • That's what I said, I tried setting it to 3 in both, then ran the commands. Still not reflecting..

    – SexyBeast
    Nov 21 '18 at 18:20











  • @SexyBeast but did you also run SET foo bar (in any one of the clients) after setting both databases to 3?

    – felipecgonc
    Nov 21 '18 at 18:24











  • Yes. Did that. And still not reflecting! :(

    – SexyBeast
    Nov 21 '18 at 18:26
















0














It seems to me that you are accessing (setting/getting values) through different dbs in your redis-cli and your redis-py instance. redis servers can have multiple key-value stores (or "tables") completely isolated from one another. These are referred throughout the documentation as db, and are uniquely identified by integers.



If you are instancing redis-py exactly as in your code snippet, with:



import redis
r = redis.StrictRedis()


Then you are using the constructor's default value for db, which is 0. (See documentation)



If the values differ between the Python implementation and redis-cli, then most likely your command line client is running on a different dbthan 0. You can check which db you are working on with the command CLIENT LIST, which will return your current database id.



To switch to the same database as the Python implementation, just run on your redis-cli:



SELECT 0


(See documentation)



Or, alternatively, you can call your redis-py constructor with the desired db parameter:



r = redis.StrictRedis(db=3) # 3 is an example value for your redis-cli's working db





share|improve this answer
























  • Thanks. I instantiated it with db value as 3 in Python, and set it to so in Redis as well: SELECT 3. Output: 127.0.0.1:6379[3]> get foo (nil)

    – SexyBeast
    Nov 21 '18 at 17:37













  • @SexyBeast your redis-py database value was definitely set to 0, whereas you don't know which database your redis-cli was using, so you can't expect to be able to get the same value with 100% certainty. Try running SELECT 0 and then GET foo in your redis-cli

    – felipecgonc
    Nov 21 '18 at 18:17











  • That's what I said, I tried setting it to 3 in both, then ran the commands. Still not reflecting..

    – SexyBeast
    Nov 21 '18 at 18:20











  • @SexyBeast but did you also run SET foo bar (in any one of the clients) after setting both databases to 3?

    – felipecgonc
    Nov 21 '18 at 18:24











  • Yes. Did that. And still not reflecting! :(

    – SexyBeast
    Nov 21 '18 at 18:26














0












0








0







It seems to me that you are accessing (setting/getting values) through different dbs in your redis-cli and your redis-py instance. redis servers can have multiple key-value stores (or "tables") completely isolated from one another. These are referred throughout the documentation as db, and are uniquely identified by integers.



If you are instancing redis-py exactly as in your code snippet, with:



import redis
r = redis.StrictRedis()


Then you are using the constructor's default value for db, which is 0. (See documentation)



If the values differ between the Python implementation and redis-cli, then most likely your command line client is running on a different dbthan 0. You can check which db you are working on with the command CLIENT LIST, which will return your current database id.



To switch to the same database as the Python implementation, just run on your redis-cli:



SELECT 0


(See documentation)



Or, alternatively, you can call your redis-py constructor with the desired db parameter:



r = redis.StrictRedis(db=3) # 3 is an example value for your redis-cli's working db





share|improve this answer













It seems to me that you are accessing (setting/getting values) through different dbs in your redis-cli and your redis-py instance. redis servers can have multiple key-value stores (or "tables") completely isolated from one another. These are referred throughout the documentation as db, and are uniquely identified by integers.



If you are instancing redis-py exactly as in your code snippet, with:



import redis
r = redis.StrictRedis()


Then you are using the constructor's default value for db, which is 0. (See documentation)



If the values differ between the Python implementation and redis-cli, then most likely your command line client is running on a different dbthan 0. You can check which db you are working on with the command CLIENT LIST, which will return your current database id.



To switch to the same database as the Python implementation, just run on your redis-cli:



SELECT 0


(See documentation)



Or, alternatively, you can call your redis-py constructor with the desired db parameter:



r = redis.StrictRedis(db=3) # 3 is an example value for your redis-cli's working db






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 16:45









felipecgoncfelipecgonc

465




465













  • Thanks. I instantiated it with db value as 3 in Python, and set it to so in Redis as well: SELECT 3. Output: 127.0.0.1:6379[3]> get foo (nil)

    – SexyBeast
    Nov 21 '18 at 17:37













  • @SexyBeast your redis-py database value was definitely set to 0, whereas you don't know which database your redis-cli was using, so you can't expect to be able to get the same value with 100% certainty. Try running SELECT 0 and then GET foo in your redis-cli

    – felipecgonc
    Nov 21 '18 at 18:17











  • That's what I said, I tried setting it to 3 in both, then ran the commands. Still not reflecting..

    – SexyBeast
    Nov 21 '18 at 18:20











  • @SexyBeast but did you also run SET foo bar (in any one of the clients) after setting both databases to 3?

    – felipecgonc
    Nov 21 '18 at 18:24











  • Yes. Did that. And still not reflecting! :(

    – SexyBeast
    Nov 21 '18 at 18:26



















  • Thanks. I instantiated it with db value as 3 in Python, and set it to so in Redis as well: SELECT 3. Output: 127.0.0.1:6379[3]> get foo (nil)

    – SexyBeast
    Nov 21 '18 at 17:37













  • @SexyBeast your redis-py database value was definitely set to 0, whereas you don't know which database your redis-cli was using, so you can't expect to be able to get the same value with 100% certainty. Try running SELECT 0 and then GET foo in your redis-cli

    – felipecgonc
    Nov 21 '18 at 18:17











  • That's what I said, I tried setting it to 3 in both, then ran the commands. Still not reflecting..

    – SexyBeast
    Nov 21 '18 at 18:20











  • @SexyBeast but did you also run SET foo bar (in any one of the clients) after setting both databases to 3?

    – felipecgonc
    Nov 21 '18 at 18:24











  • Yes. Did that. And still not reflecting! :(

    – SexyBeast
    Nov 21 '18 at 18:26

















Thanks. I instantiated it with db value as 3 in Python, and set it to so in Redis as well: SELECT 3. Output: 127.0.0.1:6379[3]> get foo (nil)

– SexyBeast
Nov 21 '18 at 17:37







Thanks. I instantiated it with db value as 3 in Python, and set it to so in Redis as well: SELECT 3. Output: 127.0.0.1:6379[3]> get foo (nil)

– SexyBeast
Nov 21 '18 at 17:37















@SexyBeast your redis-py database value was definitely set to 0, whereas you don't know which database your redis-cli was using, so you can't expect to be able to get the same value with 100% certainty. Try running SELECT 0 and then GET foo in your redis-cli

– felipecgonc
Nov 21 '18 at 18:17





@SexyBeast your redis-py database value was definitely set to 0, whereas you don't know which database your redis-cli was using, so you can't expect to be able to get the same value with 100% certainty. Try running SELECT 0 and then GET foo in your redis-cli

– felipecgonc
Nov 21 '18 at 18:17













That's what I said, I tried setting it to 3 in both, then ran the commands. Still not reflecting..

– SexyBeast
Nov 21 '18 at 18:20





That's what I said, I tried setting it to 3 in both, then ran the commands. Still not reflecting..

– SexyBeast
Nov 21 '18 at 18:20













@SexyBeast but did you also run SET foo bar (in any one of the clients) after setting both databases to 3?

– felipecgonc
Nov 21 '18 at 18:24





@SexyBeast but did you also run SET foo bar (in any one of the clients) after setting both databases to 3?

– felipecgonc
Nov 21 '18 at 18:24













Yes. Did that. And still not reflecting! :(

– SexyBeast
Nov 21 '18 at 18:26





Yes. Did that. And still not reflecting! :(

– SexyBeast
Nov 21 '18 at 18:26


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416131%2fredis-values-set-from-python-are-not-reflecting-in-redis-client%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga